[Haskell-beginners] Forcing evalation in the IO Monad
Philip Scott
haskell-beginners at foo.me.uk
Fri Apr 16 09:40:17 EDT 2010
Hi folks,
This question is so trivial it must have been answered before, but I
have been googling all morning to no avail so please bear with me. I've
been wading through mires of $! and seq, deepSeq, $!! etc.. and I have
leaned a lot of useful stuff about lazy evaluation - but I haven't been
able to solve my problem.. What I would like to do is to force an
expression to be fully evaluated to normal form, from inside the IO
monad, right there and then.
For example, in GHCI, calling putStrLn does just what I want:
Debug.Trace Prelude> let a = trace "Hello" 42
Debug.Trace Prelude> putStrLn $ show a
Hello
42
Except that it only takes showable things, and it puts an annoying
message on the screen.
What I want is something like putStrLn that doesn't print anything, and
takes any type as its input, evaluates it to normal form and then does
nothing else. It might be called something like 'evaluate' have a type
like this
evaluate :: a -> IO()
It _must_ exist - and it _must_ be easier to find this sort of thing
than I am making it, or else how did all you haskell gurus attain your
status? Am I missing something :)
All the best,
Philip
More information about the Beginners
mailing list