Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Re: Forcing evalation in the IO Monad (Daniel Fischer)


----------------------------------------------------------------------

Message: 1
Date: Fri, 16 Apr 2010 17:22:16 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Re: Forcing evalation in the IO Monad
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

Am Freitag 16 April 2010 17:00:57 schrieb Philip Scott:
>
> 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?).


Prelude Control.Exception> let lst = [undefined,undefined] :: [Bool]
Prelude Control.Exception> evaluate lst >>= putStrLn . take 1 . show
[
Prelude Control.Exception> evaluate lst >>= print
[*** Exception: Prelude.undefined

Prelude Control.Exception Debug.Trace> let a = trace "Hello" 42
Prelude Control.Exception Debug.Trace> let b = trace "Frank" [a]
Prelude Control.Exception Debug.Trace> evaluate b
Frank
[Hello
42]
Prelude Control.Exception Debug.Trace> let a = trace "Hello" 42
Prelude Control.Exception Debug.Trace> let b = trace "Frank" [a]
Prelude Control.Exception Debug.Trace> evaluate b >>= print . null
Frank
False

a is only evaluated when it's needed for printing here.

For most number types, weak head normal form is already normal form.
You can only spot the difference on types with more than one constructor or 
a lazy field in a constructor.

>
> - Philip



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 22, Issue 25
*****************************************

Reply via email to