[Haskell-beginners] homogeneous value list

Yitzchak Gale gale at sefer.org
Sun Mar 14 07:18:21 EDT 2010


Brent Yorgey wrote:
>>> I would argue that it's good practice simply to never call head at
>>> all.  I stopped a while ago, and I haven't missed it. =)

Daniel Fischer wrote:
>> I would argue that in
>> snub = map head . group . sort
>> and the like, calling head is perfectly cromulent. But apart from that, I
>> don't remember using head in the last years.

> Ah, true, I guess that's the one place I've used head as well. =)

snub = concatMap (take 1) . group . sort

Perhaps a tiny bit slower if it doesn't get optimized. But I consider
using head a premature optimization.

listToMaybe is another helpful tool for getting rid of head.

Enjoy,
Yitz


More information about the Beginners mailing list