我是Haskell的新手,我发现很难理解它。我试图通过测试一个函数来理解别人的代码,但无法弄清楚如何做到这一点。功能如下:
same_ratio_dec_inf a b c d e f g h =
case z_eq_dec (zmult a f) (zmult b e) of
LLeft ->
(case z_eq_dec (zmult b g) (zmult c f) of
LLeft ->
(case z_eq_dec (zmult c h) (zmult d g) of
LLeft ->
(case z_eq_dec (zmult a g) (zmult c e) of
LLeft ->
(case z_eq_dec (zmult a h) (zmult d e) of
LLeft -> z_eq_dec (zmult b h) (zmult d f)
RRight -> RRight)
RRight -> RRight)
RRight -> RRight)
RRight -> RRight)
RRight -> RRight
如果我“:t same_ratio_dec_inf”我得到:
same_ratio_dec_inf :: Z -> Z -> Z -> Z -> Z -> Z -> Z -> Z -> Sumbool
Sumbool的定义如下:
数据Sumbool = LLeft | RRight
我看到一些其他代码,其中Z输入如下:
showQ (qquadratic (toZ a) (toZ b) (toZ c) (toZ d) (toZ e) (toZ f) (toZ g) (toZ h) (toQ x) (toQ y))
所以我认为我可以为函数提供正确的输入......我不清楚如何生成和显示输出。 任何帮助,将不胜感激。 谢谢!
编辑:可在此处找到整个代码:https://github.com/coq-contribs/qarith-stern-brocot/blob/master/quadratic.hs
答案 0 :(得分:0)
我不清楚你有什么困惑,但我尝试了一些东西。也许有帮助。
在您的链接(https://github.com/coq-contribs/qarith-stern-brocot/blob/master/quadratic.hs)中有qquadratic_
的一些用法:
lazy_plus_ x y = qquadratic_ 0 1 1 0 0 0 0 1 x y
lazy_mult_ x y = qquadratic_ 1 0 0 0 0 0 0 1 x y
...
我想知道预期的x
y
类型,所以我:
*Quadratic> :t qquadratic_
qquadratic_
:: (Integral a, Integral a1, Integral a2, Integral a3, Integral a4,
Integral a5, Integral a6, Integral a7) =>
a
-> a1
-> a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> [Char]
-> [Char]
-> [Char]
我们得到:1。x
和y
是字符串(具有某种所需格式)2。qquadratic_
最终将返回字符串(lazy_plus_
,{{1} }},...),可以很容易地看到输出。
然后我尝试构建一些lazy_mult_
和x
。根据{{1}}的定义,它们被送到y
,
toQ
我猜到了一些意见:
toQ
如果您知道原始Coq程序的作用,您可能会得到一些有意义的输入。