[Haskell-cafe] A tale of Project Euler
Bulat Ziganshin
bulat.ziganshin at gmail.com
Fri Nov 30 00:54:45 EST 2007
Hello Andrew,
Thursday, November 29, 2007, 9:43:48 PM, you wrote:
>> Fifth thing: better use an STUArray, don't drag IO in if it's not necessary.
>>
> I don't understand the ST monad.
it's just a subset of IO monad, with renamed operations
the subset is selected in the way that guarantees reference
transparency, i.e. compiler is able to do more checks that your
program is correct. so, instead of writing
main = do a <- newArray
writeArray a 1 3.14
x <- readArray a 1
print x
you can write
main = do x <- runST (do a <- newArray
writeArray a 1 3.14
x <- readArray a 1
return x)
print x
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list