動作しない私は、これは、例えば、正常に動作するようです一見無害型クラスのインスタンスは、型クラスで遊ん
class Pair p a | p -> a where
one :: p -> a
two :: p -> a
を思い付い
instance Pair [a] a where
one [x,_] = x
two [_,y] = y
しかし、私はタプルに問題があります。以下の定義はコンパイルにもかかわらず、私は予想通り...
instance Pair (a,a) a where
one p = fst p
two p = snd p
...私はそれを使用することはできません。正しくインスタンスを定義する方法が
main = print $ two (3, 4)
No instance for (Pair (t, t1) a)
arising from a use of `two' at src\Main.hs:593:15-23
Possible fix: add an instance declaration for (Pair (t, t1) a)
In the second argument of `($)', namely `two (3, 4)'
In the expression: print $ two (3, 4)
In the definition of `main': main = print $ two (3, 4)
ありますか?または、newtype
ラッパーに頼らざるを得ませんか?
ありがとう、非常に面白い! – Landei