Kiedy próbuję załadować następujący kod pod GHC 7.4.1:newtype wokół ST powoduje błąd typu
{-# 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
nie powiedzie się z następującym komunikatem:
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
Dlaczego to się nie uda, gdy M
to tylko opakowanie o numerze ST
?
(. Mój rzeczywisty program ma kilka transformatorów ułożone na – to tylko minimalny przypadek)
EDIT: Wydaje dodanie let
rozwiązuje problem:
runM m = let M m' = m in runST m
Jednakże, jeśli TypeFamilies
jest włączony (jak to jest w moim prawdziwym kodzie), to znowu się nie powiedzie.
Wierzę, że to dlatego, że – jozefg
Z powodu czego? –
Przepraszam, odrzuciłem moją hipotezę :(( – jozefg