ho notato che GHC voleva una firma tipo che credo dovrebbe essere dedotto. Ho ridotto al minimo il mio esempio fino a questo, che quasi certamente non fa nulla significativo (Non consiglio esecuzione su tuoi preferiti tipi):Type Inference in Patterns
{-# 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
Senza una firma di tipo sulla definizione di y
, ottengo l'errore:
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.
la cattura è avvenuta dalla restrizione monomorfismo temuto su più occasioni, ho acceso NoMonomorphismRestriction
, ma questo non cambia il comportamento.
Perché il tipo di y
non dedurre essere il tipo di uscita della funzione?
Non ho la minima idea. Ho trovato un fatto divertente però: se si aggiunge "_ -> y" sotto "Just Refl -> y", funziona. –
@ AndrásKovács Strano! Ma '_ -> errore" "' * non funziona *! – crockeea
@leftaroundabout citato in [questa risposta] (http://stackoverflow.com/a/24725229/925978) che "Ancora, gli stessi [problemi di inferenza] possono comparire anche senza la limitazione del monomorfismo nel codice RankNTypes, non può essere evitato completamente. " Qualche idea su cosa sia esattamente il mio codice che potrebbe farla cadere in questa categoria di "problemi problematici di RankNTypes"? – crockeea