모든 공통된 동작을하고 싶습니다. 내 문제는 다음 코드에 설명되어 있습니다 :Haskell 컨텍스트 오류에서 ...을 추론 할 수 없습니다.
example.hs:19:14: Could not deduce (a ~ T) from the context (A a, B b) bound by the type signature for method :: (A a, B b) => Y -> a -> b at example.hs:(17,5)-(19,18) `a' is a rigid type variable bound by the type signature for method :: (A a, B b) => Y -> a -> b at example.hs:17:5 In the pattern: N In an equation for `method': method _ N = R In the instance declaration for `X Y' example.hs:19:18: Could not deduce (b ~ U) from the context (A a, B b) bound by the type signature for method :: (A a, B b) => Y -> a -> b at example.hs:(17,5)-(19,18) `b' is a rigid type variable bound by the type signature for method :: (A a, B b) => Y -> a -> b at example.hs:17:5 In the expression: R In an equation for `method': method _ N = R In the instance declaration for `X Y' Failed, modules loaded: none.
나는이 경우 무엇을해야 하는지를 딱하다 :이 모듈을로드 할 때
class A a class B b class X x where method :: (A a, B b) => x -> a -> b data T = L | M | N data U = P | Q | R instance A T instance B U data Y = ZZZ instance X Y where method _ L = P method _ M = Q method _ N = R
, 나는 다음과 같은 오류가 발생합니다. T와 U가 A와 B의 인스턴스 인 경우에도이 오류가 발생합니다. method
에서 고정 유형 값을 반환 할 수없는 경우이 부분을 어떻게 코딩합니까?
가능한 데이터 형식 목록 : "컨텍스트에서 (a ~ SomeType)을 추론 할 수 없습니다 (SomeTypeclass a)"] (http://stackoverflow.com/questions/5453514/lists-of-data-types -could-not-deduce-a-sometype-from-the-context-sometype) – Landei