
Thanks guys, I thinks I can stop trying to get things out of IO now.
Instead I should see if I could make my monad as an instance of MonadIO, so
I can use liftIO, which should be safe I believe.
2011-5-6下午3:46,Daniel Fischer
On Friday 06 May 2011 05:28:35, Felipe Almeida Lessa wrote:
If you are a beginner, you should never use anything that starts with
'unsafe'.
Basically yes, use something beginning with 'unsafe' only when you know why
it's not unsafe in your specific case.
But of course there are different levels of unsafeness,
Data.Array.Base.unsafeAt for example is relatively benign (same as in other
languages: if you don't let the compiler check array bounds and screw your
check up, you can get nonsense or segfaults, but it's relatively easy to
understand and control).
And you should never use 'unsafePerformIO'. And you
should NEVER use 'unsafeCoerce'.
Those two indeed have a different calibre, use them only
whenYouReallyKnowWhatYouAreDoing.
They have their uses and sometimes are the right thing, but like goto, in
most cases one is tempted to use them, one shouldn't.
Cheers, =)
--
Felipe.