Martin Norbäck d95mback@dtek.chalmers.se
25 Jan 2002 09:12:56 +0100


fre 2002-01-25 klockan 08.27 skrev David Feuer:
> Martin Said:
> 
> > Those two constructs are not the same
> 
> > Compare
> 
> > newtype T1 = C1 Bool
> >  data    T2 = C2 !Bool

> The report says clearly that for a newtype like T1,
> C1 _|_ = _|_
> This is the same as for T2 and C2.

No.

C1 _|_ is the same as _|_ representation-wise (not type-wise).
C2 _|_ is C2 _|_.

If you imagine the computer's memory, when you store the value (C1 True)
you just store (True). When you store the value (C2 True) you store (C2
True).

So you can't choose whether to match strictly or lazily on C1, because
you don't match on C1, because C1 is never stored in memory. It's simply
a typing trick.

That's why it's more efficient to use newtype than data. You don't need
to handle the constructor because the type-checker removes all traces of
it.

Regards,

	Martin

-- 
[ http://www.dtek.chalmers.se/~d95mback/ ] [ PGP: 0x453504F1 ] [ UIN:
4439498 ]
    Opinions expressed above are mine, and not those of my future
employees.
SIGBORE: Signature boring error, core dumped