[Haskell-beginners] homogeneous value list
daniel.is.fischer at web.de
Fri Mar 12 11:15:24 EST 2010
Am Freitag 12 März 2010 15:40:36 schrieb Brent Yorgey:
> On Fri, Mar 12, 2010 at 03:31:54PM +0100, Daniel Fischer wrote:
> > Am Freitag 12 März 2010 15:25:48 schrieb Salil Wadnerkar:
> > > On Fri, Mar 12, 2010 at 10:21 PM, Ozgur Akgun <ozgurakgun at gmail.com>
> > wrote:
> > > > Another boring variant from me then.
> > > >
> > > > isHomogeneous xs = all (first==) xs
> > > > where first = head xs
> > >
> > > Shouldn't
> > > head xs
> > > give an exception on an empty list?
> > Only if it's demanded, which it isn't here, since all doesn't look at
> > the condition when facing an empty list.
> > But it's good practice to never call head on a list which may be
> > empty, so I wouldn't like Ozgur's variant in real code. It's great for
> > golf, though
> > :D
> 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. =)
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.
More information about the Beginners