[Haskell-cafe] Re: Is "take" behaving correctly?
Andrew Coppin
andrewcoppin at btinternet.com
Wed Sep 12 14:17:38 EDT 2007
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...
More information about the Haskell-Cafe
mailing list