In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and (a, (b, c)).
If all pattern matches of all products was always irrefutable, then there would be no difference, and (a, b, c) could be syntactic sugar for (a, (b, c)).
Why did Haskell choose to lift type products?
Why did Haskell choose to lift type products?
You can justify this design choice without appealing to laziness or refutable patterns. The same design choice is made ML for reasons of supporting polymorphism. Consider
fst (x, y) = x
snd (x, y) = y
Now if (a, (b, c))
is syntactic sugar for (a, b, c)
, it's quite difficult to see how to specialize fst
and snd
to take this type as an argument. But
fst :: (a, (b, c)) -> a
snd :: (a, (b, c)) -> (b, c)
are perfectly reasonable. Because polymorphic functions like fst
and snd
are so incredibly useful, both Haskell and ML give the programmer the ability to distinguish (a, (b, c))
and ((a, b), c)
from (a, b, c)
.
(For people who care about costs, the type structure is also a reasonable guide to the size of the type and the number of indirections (loads) needed to get its elements. Some programmers need or want to know about such things and to have some small degree of control over them.)
One reason is that implementing seq
for an unlifted product requires parallel/interleaved computation, since seq (a, b) True
would be supposed to be True
if and only if at least one of a
and b
is non-bottom. You might not find this reason terribly convincing, depending on how you feel about seq
, but of course polymorphic seq
is by definition a part of Haskell...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With