[Haskell-cafe] OOP'er with (hopefully) trivial questions.....

Tim Chevalier catamorphism at gmail.com
Mon Dec 17 13:26:59 EST 2007

On 12/17/07, Evan Laforge <qdunkan at gmail.com> wrote:
> I'm sure there's a trivial explanation for this, but here's something
> that I've always kind of wondered about:  Given a single constructor
> type like "data X = X A B C" can't that be transformed into "newtype X
> = X (A, B, C)"?  There must be some difference, because if there
> weren't we could transform all single constructor types that way, and
> dispense with newtype entirely.

Strictness. In newtype X = X A, the A field is strict. In data X = X
A, the A field is lazy. So the compiler can't just turn all
single-constructor "data" types into "newtypes". (To generalize, if
you were going to allow newtypes like "newtype X = X (A, B, C)", the
tuple would be unboxed, and you'd have the same strictness/laziness

This is explained in section 4.2.3 of the H98 Report:


Tim Chevalier * catamorphism.org * Often in error, never in doubt
"Do we learn from our mistakes? I surely hope not / Takes all the fun
out of making them again."--Trout Fishing In America

More information about the Haskell-Cafe mailing list