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

Tim Chevalier catamorphism at gmail.com
Mon Dec 17 13:33:49 EST 2007

On 12/17/07, Evan Laforge <qdunkan at gmail.com> wrote:
> Oops, nevermind, I just saw the other thread and link to
> http://www.haskell.org/haskellwiki/Newtype.  Ok, so that seems like a
> pretty subtle diffenence... I'm assuming the rationale behind
> differentiating between a single constructor data and newtype is so
> that data types don't suddenly change their behaviour around undefined
> when they have only one constructor.  I would find example y3
> surprising if I came across it in real code!

It's not that subtle if you think about what newtype is for. Newtype
is like "type", except that you're not just declaring a type synonym,
but asking the typechecker to check that you don't use the synonym
interchangeably with the type it's standing in for.

Types declared with newtype and with type are supposed to act exactly
the same way at runtime. In order to act exactly the same way at
runtime, if you write newtype X = X A, X _|_ has to be
indistinguishable from _|_ at runtime. In other words, the data
constructor X has to be strict. In types declared with "data",
constructors are lazy -- if they weren't, you wouldn't be programming
in Haskell.


Tim Chevalier * catamorphism.org * Often in error, never in doubt
"People. Can't live with 'em, can't legally set fire to 'em." -- Sheree Schrager

More information about the Haskell-Cafe mailing list