[Haskell-beginners] homogeneous value list

Brent Yorgey byorgey at seas.upenn.edu
Sat Mar 13 15:08:26 EST 2010


On Fri, Mar 12, 2010 at 05:15:24PM +0100, Daniel Fischer wrote:
> 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. =)
> >
> > -Brent
> 
> 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. =)

-Brent


More information about the Beginners mailing list