On Dec 17, 2007 8:51 AM, Bayley, Alistair <<a href="mailto:Alistair_Bayley@invescoperpetual.co.uk">Alistair_Bayley@invescoperpetual.co.uk</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As an aside, I was wondering exactly what the differences are between<br>newtype and data i.e. between<br><br>> newtype A a = A a<br><br>and<br><br>> data A a = A a<br><br>According to:<br> <a href="http://www.haskell.org/onlinereport/decls.html#sect4.2.3" target="_blank">
http://www.haskell.org/onlinereport/decls.html#sect4.2.3</a><br>newtype is, umm, stricter than data i.e. newtype A undefined =<br>undefined, but data A undefined = A undefined. Other than that, newtype<br>just seems to be an optimization hint. Is that a more-or-less correct
<br>interpretation?<br></blockquote></div><br>Pretty much. Newtype is nice to have, but I don't think there's any program you can write that couldn't be rewritten to use data (with a possible loss of efficiency).
<br><br>The difference that surprised me is the difference between <br><br> newtype A a = A a<br><br>and<br><br> data A a = A !a<br><br>If we define a function like this,<br><br> seqA (A a) = ()<br clear="all"><br>
Under the first definition of A, <br><br> seqA undefined = ()<br><br>Under the second,<br><br> seqA undefined = undefined<br><br>The difference is that pattern-matching a newtype doesn't do any evaluation.<br><br>
-- <br>Dave Menendez <<a href="mailto:firstname.lastname@example.org">email@example.com</a>><br><<a href="http://www.eyrie.org/~zednenem/">http://www.eyrie.org/~zednenem/</a>>