[Haskell-beginners] homogeneous value list

Ozgur Akgun ozgurakgun at gmail.com
Fri Mar 12 09:29:13 EST 2010


Should it? I tried to explain it, but if you are not convinced just give it
a try.


>
> Guess what? You do not need the special case for [], because "all _ [] =
> True" allways. So if the list is empty, it won't even try evaluating
> "first".
>

On 12 March 2010 14:25, Salil Wadnerkar <rohshall at gmail.com> wrote:

> 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?
>
>
>
> >
> > Guess what? You do not need the special case for [], because "all _ [] =
> > True" allways. So if the list is empty, it won't even try evaluating
> > "first".
> >
> > Cheers,
> >
> > On 12 March 2010 14:08, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> >>
> >> Am Freitag 12 März 2010 14:41:11 schrieb Daniel Fischer:
> >> >
> >> > isHomogeneous :: Eq a => [a] -> Bool
> >> > isHomogeneous [] = True
> >> > isHomogeneous (x:xs) = all (== x) xs
> >> >
> >>
> >> Variant, getting rid of the special case for an empty list:
> >>
> >> isHomogeneous :: Eq a => [a] -> Bool
> >> isHomogeneous xs = and (zipWith (==) xs (drop 1 xs))
> >> _______________________________________________
> >> Beginners mailing list
> >> Beginners at haskell.org
> >> http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> >
> > --
> > Ozgur Akgun
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
>



-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100312/3cb52c2d/attachment.html


More information about the Beginners mailing list