On Dec 17, 2007 8:51 AM, Bayley, Alistair &lt;<a href="mailto:Alistair_Bayley@invescoperpetual.co.uk">Alistair_Bayley@invescoperpetual.co.uk</a>&gt; 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>&gt; newtype A a = A a<br><br>and<br><br>&gt; data A a = A a<br><br>According to:<br> &nbsp;<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&#39;t think there&#39;s any program you can write that couldn&#39;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>&nbsp; &nbsp; newtype A a = A a<br><br>and<br><br>&nbsp;&nbsp;&nbsp; data A a = A !a<br><br>If we define a function like this,<br><br>&nbsp;&nbsp;&nbsp; seqA (A a) = ()<br clear="all"><br>
Under the first definition of A, <br><br>&nbsp;&nbsp;&nbsp; seqA undefined = ()<br><br>Under the second,<br><br>&nbsp;&nbsp; seqA undefined = undefined<br><br>The difference is that pattern-matching a newtype doesn&#39;t do any evaluation.<br><br>
-- <br>Dave Menendez &lt;<a href="mailto:dave@zednenem.com">dave@zednenem.com</a>&gt;<br>&lt;<a href="http://www.eyrie.org/~zednenem/">http://www.eyrie.org/~zednenem/</a>&gt;