import Data.Nat.Views
total toBinary : Nat -> String
toBinary k with (halfRec k)
toBinary Z | HalfRecZ = ""
toBinary (n + n) | (HalfRecEven rec) = (toBinary n | rec) ++ "0"
toBinary (S (n + n)) | (HalfRecOdd rec) = (toBinary n | rec) ++ "1"
当使用表达式toBinary 2
在REPL中测试上述功能时,将打印以下内容。
prim__concat (with block in Exercises.toBinary 1
(with block in with block in Data.Nat.Views.halfRec 0
(half 0)
(Access (\z, zLTy =>
Prelude.WellFounded.sizeAccessible, acc Nat
2
(constructor of Prelude.WellFounded.Sized (\meth =>
meth))
1
z
(lteTransitive zLTy
(LTESucc LTEZero))))))
"0" : String
当我运行:exec toBinary 2
时,会打印出"10"
的预期结果。
任何人都可以解释发生了什么事吗?