<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 17 Dec 2007, at 7:39 AM, David Menendez wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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>  <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.</blockquote><div><br class="webkit-block-placeholder"></div></div><div>So there is a program (or, rather, type) you can write with newtype that can't be written with data:</div><div><br class="webkit-block-placeholder"></div><div>newtype T = T T</div><div><br class="webkit-block-placeholder"></div><div>jcc</div><div><br class="webkit-block-placeholder"></div></body></html>