[Haskell-cafe] newtype is superfluous
Lennart Augustsson
lennart at augustsson.net
Sat Oct 15 09:03:50 EDT 2005
Wolfgang Jeltsch wrote:
> Am Samstag, 15. Oktober 2005 08:31 schrieb Bulat Ziganshin:
>
>>Hello Haskell,
>>
>> number of type definition statements in Haskell (data, type, newtype) is
>>a bit too large. at least, newtype definition seems to be superfluous - it
>>can be replaced by the same `data` definition:
>>
>>newtype A = A Int
>>and
>>data A = A Int
>>
>>is equal, excluding for internal representation.
>
>
> This is not true. With newtype, A _|_ is _|_, with data, A _|_ is not _|_.
> But as far as I know, the above newtype declaration is equivalent to this:
>
> data A = A !Int
Alas, Haskell is more subtle than that. Which is why newtype exists.
Try
case A _|_ of A _ -> 1
with the two versions of A to see the difference.
-- Lennart
More information about the Haskell-Cafe
mailing list