On 12/17/07, Evan Laforge <[EMAIL PROTECTED]> 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.

Cheers,
Tim

-- 
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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to