On Dec 17, 2007 8:51 AM, Bayley, Alistair < [EMAIL PROTECTED]> wrote:
> As an aside, I was wondering exactly what the differences are between > newtype and data i.e. between > > > newtype A a = A a > > and > > > data A a = A a > > According to: > http://www.haskell.org/onlinereport/decls.html#sect4.2.3 > newtype is, umm, stricter than data i.e. newtype A undefined = > undefined, but data A undefined = A undefined. Other than that, newtype > just seems to be an optimization hint. Is that a more-or-less correct > interpretation? > 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). The difference that surprised me is the difference between newtype A a = A a and data A a = A !a If we define a function like this, seqA (A a) = () Under the first definition of A, seqA undefined = () Under the second, seqA undefined = undefined The difference is that pattern-matching a newtype doesn't do any evaluation. -- Dave Menendez <[EMAIL PROTECTED]> <http://www.eyrie.org/~zednenem/>
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe