3
ハスケル初心者はこちら。私は完全な加算のための関数を書くためにいくつかの助けが必要です。 私は、次の持っている: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)'
しかし、あなたの関数は2つの要素を返しませんか? –
私はあなたが '\' xor \ ''(それを中置にするのに必要なバッククォート)を探しているかもしれないと思います。今では 'xor'と' b'の2つの引数に 'a'を適用しています。 – ryachza
現在、関数全体を実装して、それが失敗する理由をデバッグしようとしています。あなたが小さいものから始めるならば、自分でもっと楽にすることができます。たとえば、 'fulladder a b c = True ++ True'は、最初のダミー実装として良いでしょう。失敗しますが、検索するのがずっと短くて簡単です。これを修正したら、完全な表現に達するまで 'fulladder a b c =(True xまたはTrue、True)'などに展開することができます。 –