Wenn ich versuche, den folgenden Code unter GHC 7.4.1 zu laden:newtype um ST verursacht Typ Fehler
{-# LANGUAGE RankNTypes #-}
import Control.Monad.ST
newtype M s a = M { unM :: ST s a }
runM :: (forall s. M s a) -> a
runM (M m) = runST m
Es mit der folgenden Meldung fehlschlägt:
test.hs:9:14:
Couldn't match type `s0' with `s'
because type variable `s' would escape its scope
This (rigid, skolem) type variable is bound by
a type expected by the context: ST s a
The following variables have types that mention s0
m :: ST s0 a (bound at test.hs:9:9)
In the first argument of `runST', namely `m'
In the expression: runST m
In an equation for `runM': runM (M m) = runST m
Warum dies nicht versagt, wenn M
ist nur ein Wrapper um ST
?
(. Mein eigentliches Programm hat ein paar Transformatoren auf – gestapelt ist dies nur ein Minimalfall)
EDIT: Es scheint, das Hinzufügen eines let
behebt das Problem:
runM m = let M m' = m in runST m
Wenn jedoch TypeFamilies
aktiviert ist (wie es in meinem echten Code ist), schlägt es erneut fehl.
Ich glaube, das ist, weil – jozefg
Wegen was? –
Entschuldigung, ich widerlegte meine eigene Hypothese :( – jozefg