3
Haskell新手在这里。我需要一些帮助,为全加器编写一个函数。 我有以下几点:Haskell的全加器
xor :: Bool -> Bool -> Bool
xor True False = True
xor False True = True
xor _ _ = False
fulladder :: Bool -> Bool -> Bool ->(Bool, Bool)
fulladder a b c = c xor (a xor b) ++ (a&&b) || ((a xor b) && c)
,我发现了以下错误:
* Couldn't match expected type `(Bool -> Bool -> Bool)
-> Bool -> Bool'
with actual type `Bool'
* The function `a' is applied to two arguments,
but its type `Bool' has none
In the first argument of `(&&)', namely `(a xor b)'
In the second argument of `(||)', namely `((a xor b) && c)'
但是你的函数不返回两个元素? –
我认为你可能正在寻找'\'xor \''(使其成为中缀所需的反引号)。因为现在你正在对'xor'和'b'这两个参数应用'a'。 – ryachza
您目前实现了一个完整的功能,然后尝试调试它失败的原因。如果你从小处开始建设,你可以让自己变得更容易。例如,'fulladder a b c = True ++ True'可能是一个很好的第一个虚拟实现:它失败了,但它更短,更容易查找。一旦你解决了这个问题,你可以扩展到'ful = bc =(True xor True,True)',等等,直到你完全表达。 –