[Haskell-beginners] Re: Forcing evalation in the IO Monad
Philip Scott
pscott at foo.me.uk
Fri Apr 16 11:09:07 EDT 2010
Philip Scott wrote
> The documentation says that, but it does appear to go deeper than just
> one level:
>
> Debug.Trace Prelude Control.Exception> let a = trace "Hello" 42
> Debug.Trace Prelude Control.Exception> let b = trace "Frank" (a * 2)
> Debug.Trace Prelude Control.Exception> evaluate b
> Frank
> Hello
> 84
>
> Perhaps it specifies WHNF in case you 'evaluate' something which
> doesn't have a HNF (like a partially applied function?).
It is actually quite interesting what it does in this case:
> let f x = trace "jingle" (x * 2)
> a <- evaluate (f)
> :t f
f :: (Num a) => a -> a
> :t a
a :: Integer -> Integer
So it does some sort of evaluation - it has decided we're going to be
using Integers instead of Nums. I wonder what it is up to there.
More information about the Beginners
mailing list