유형 - 클래스와 장난이 작동하지 않습니다Typeclass 인스턴스 내가이 잘, 예를 작동하는 것 같다 겉으로는 결백</p> <pre><code>class Pair p a | p -> a where one :: p -> a two :: p -> a </code></pre> <p>함께했다
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