GHC가 유추해야한다고 생각하는 유형 서명을 원했습니다. 나는 거의 확실하게 의미있는 것은 (내가 좋아하는 종류에 그것을 실행하지 않는 것이 좋습니다)하지 않습니다 어떤이, 내 예를 최소화 : y
의 정의에 유형 서명없이유형의 추론
{-# LANGUAGE GADTs, RankNTypes, ScopedTypeVariables,
TypeOperators, NoMonomorphismRestriction #-}
module Foo where
import Data.Typeable
data Bar rp rq
data Foo b = Foo (Foo b)
rebar :: forall rp rq rp' rp'' . (Typeable rp', Typeable rp'')
=> Proxy rp' -> Proxy rp'' -> Foo rp -> Foo (Bar rp rq)
rebar p1 p2 (Foo x) =
-- The signature for y should be inferred...
let y = rebar p1 p2 x -- :: Foo (Bar rp rq)
-- The case statement has nothing to do with the type of y
in case (eqT :: Maybe (rp' :~: rp'')) of
Just Refl -> y
를, 나는 오류가 발생합니다 :
Foo.hs:19:20:
Couldn't match type ‘rq0’ with ‘rq’
‘rq0’ is untouchable
inside the constraints (rp' ~ rp'')
bound by a pattern with constructor
Refl :: forall (k :: BOX) (a1 :: k). a1 :~: a1,
in a case alternative
at testsuite/Foo.hs:19:12-15
‘rq’ is a rigid type variable bound by
the type signature for
rebar :: (Typeable rp', Typeable rp'') =>
Proxy rp' -> Proxy rp'' -> Foo rp -> Foo (Bar rp rq)
at testsuite/Foo.hs:12:20
Expected type: Foo (Bar rp rq)
Actual type: Foo (Bar rp rq0)
Relevant bindings include
y :: Foo (Bar rp rq0) (bound at testsuite/Foo.hs:16:7)
rebar :: Proxy rp' -> Proxy rp'' -> Foo rp -> Foo (Bar rp rq)
(bound at testsuite/Foo.hs:14:1)
In the expression: y
In a case alternative: Just Refl -> y
Failed, modules loaded: none.
여러 occassions에에 지칠대로 지친 단사 사상 제한에 의해 체포 된 데, 나는 NoMonomorphismRestriction
켜져 있지만,이 동작을 변경하지 않습니다.
y
의 유형이 함수의 출력 유형으로 추정되지 않는 이유는 무엇입니까?
나는 조금이라도 생각하지 못했습니다. 나는 재미있는 사실을 발견했다 : "Just Refl -> y"아래에 "_ -> y"를 추가하면 작동한다. –
@ AndrásKovács 이상한! 그러나'_ -> error ""'*는 작동하지 않습니다! – crockeea
@Lastaround에 대해 [이 답변] (http://stackoverflow.com/a/24725229/925978)에서 "여전히 동일한 추론 문제가 RankNTypes 코드의 단일 형태 제한 없이도 나타날 수 있습니다. 완전히 피하십시오. " 이 코드가 "문제가있는 RankNTypes"범주에 속하게되는 원인이 될 수있는 코드에 대한 의견은 무엇입니까? – crockeea