
12 Sep
2007
12 Sep
'07
6:17 p.m.
PR Stanley wrote:
Hi
The same should apply to head and tail. head or tail of [] should be [].
What does the list think?
Disagree, strongly. Its not even possible for head, since [a] -> a. Wadler's theorems for free states that if head is given an empty list the _only_ thing it can do is crash.
What's the logic behind this?
It's easy enough to define tail [] = [], but you can't write head [] = [] since [] is a *list* and head doesn't return a list. It returns a list element. And [] has no elements, so... what are you going to return? Notice that tail [] = error, yet drop 1 [] = [], which is interesting...