Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disadvantage of unlifted type products?

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?

like image 686
Peaker Avatar asked Mar 21 '10 18:03

Peaker


2 Answers

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.)

like image 118
Norman Ramsey Avatar answered Dec 01 '22 17:12

Norman Ramsey


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...

like image 23
Reid Barton Avatar answered Dec 01 '22 17:12

Reid Barton