I'm going to answer a slightly different question: "does newtype
add any semantic functionality to Haskell?". I believe the answer is "no".
Suppose we have data Td = Td !G
and newtype Tn = Tn G
. Then
Td
and Tn
have exactly the same inhabitants, i.e. the inhabitants of G
- When forced to WHNF both behave in the same way: the
g
they "contain" is forced
- They differ in how they interact with
case
but this is only syntactic. There is a direct correspondance between the two versions.
The following table explains how a newtype
Tn
can be replaced by a data
Td
in a case
statement. There's also a translation back the other way.
Tn Td
case tn of _ -> ... case td of _ -> ...
case tn of Tn _ -> ...
case tn of Tn x -> ... x ... let x1 = case tn of Td x -> x in ... x1 ...
case tn of x -> ... x ... case td of x -> ... x ...
case tn of Tn x -> x `seq` ... case td of Td _ -> ...
case tn of Tn x -> x `seq` ... x ... case td of Td x -> ... x ...
So semantically speaking I believe Haskell could have avoided adding newtype
. Syntactically speaking newtype maybe makes case
statements a less awkward, that's all.