Martin Said:
Those two constructs are not the same
Compare
newtype T1 = C1 Bool data T2 = C2 !Bool
the difference is that the constructor C1 does not exist, so only the following values exist for T1:
C1 True (which is the represented as True) C1 False (which is the represented as False) C1 _|_ (which is represented as non-termination or error)
however, for T2, another value exist, namely _|_. So, pattern matching on (T2 x) may fail it the value is _|_. You are right that semantically newtype is the same as always matching lazily on the constructor.
The report says clearly that for a newtype like T1, C1 _|_ = _|_ This is the same as for T2 and C2. As for as I can tell, the only difference in the Report between a newtype and a tuple type with a completely strict constructor is in the rules for pattern matching. So I am trying to find someone who can explain the reason for the difference in the rules! I really want to know, because I think/hope that it will help me understand certain things about how to write efficient code.
The case for a tuple type (a,b,c) for instance, is different. Here there is a constructor, you can even type it by itself, it is (,,), try ":t (,,)" in hugs or ghci.
I don't understand what you're talking about here.... Of course there's a constructor... This message has been brought to you by the letter alpha and the number pi.
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
participants (2)
-
David Feuer -
Martin Norbäck