
Ok, solved, the use of ($) was the problem. I changed it
primes :: Set Integer primes = runST (getPrimes "primes10h7.txt")
and it compiles (and works too). Nicu
-----Ursprüngliche Nachricht----- Von: Nicu Ionita [mailto:nionita@lycos.de] Gesendet: Sonntag, 9. Dezember 2007 12:12 An: 'haskell-cafe@haskell.org' Betreff: ST Monad - what's wrong?
Hi,
I'm trying to use the ST monad in order to turn an almost pure function into a pure one: reading a precalculated list of primes into a prime set. But the following code brings an error:
primes :: Set Integer primes = runST $ getPrimes "primes10h7.txt"
getPrimes :: String -> (forall s. ST s (Set Integer)) getPrimes file = do cont <- unsafeIOToST (readFile file) let set = fromList $ map read $ lines cont return set
And here is the error:
Couldn't match expected type `forall s. ST s a' against inferred type `ST s (Set Integer)' In the second argument of `($)', namely `getPrimes "primes10h7.txt"' In the expression: runST $ (getPrimes "primes10h7.txt") In the definition of `primes': primes = runST $ (getPrimes "primes10h7.txt")
Compiled with GHC 6.6.1 with extensions activated.
Nicu
participants (1)
-
Nicu Ionita