ho scritto la seguente funzione:GHC rifiuta il codice monad ST come non è in grado di unificare le variabili di tipo?
(.>=.) :: Num a => STRef s a -> a -> Bool
r .>=. x = runST $ do
v <- readSTRef r
return $ v >= x
ma quando ho provato a compilare ho ottenuto il seguente errore:
Could not deduce (s ~ s1)
from the context (Num a)
bound by the type signature for
.>=. :: Num a => STRef s a -> a -> Bool
at test.hs:(27,1)-(29,16)
`s' is a rigid type variable bound by
the type signature for .>=. :: Num a => STRef s a -> a -> Bool
at test.hs:27:1
`s1' is a rigid type variable bound by
a type expected by the context: ST s1 Bool at test.hs:27:12
Expected type: STRef s1 a
Actual type: STRef s a
In the first argument of `readSTRef', namely `r'
In a stmt of a 'do' expression: v <- readSTRef r
chiunque può aiutare?
Si noti che questo ancora non scriverò il controllo, poiché il vincolo dovrebbe essere 'Ord', non' Num'. – hammar
Grazie per averlo notato. – dave4420