[Haskell-cafe] Producing MinimumValue

Jason Dagit dagit at codersbase.com
Thu Jul 19 16:03:43 EDT 2007


On 7/19/07, Dan Weston <westondan at imageworks.com> wrote:
> Oops, you got me. I didn't even look at the third line, I just took it
> from the previous post. My first instinct actually was to write:
>
> allEqual x@(h:t) = and (zipWith (==) x t)

I prefer,

allEqual [] = True
allEqual xs = foldl1 (==) xs

But, unfortunately, it's not a one liner like yours (unless you allow
allEqual [] = undefined).

Jason

>
> but I don't think that zipWith is allowed in the question.
>
> Dan
>
>
> Antoine Latter wrote:
> > On 7/19/07, Dan Weston <westondan at imageworks.com> wrote:
> >>
> >> I would define:
> >>
> >> allEqual []         = True
> >> allEqual [_]        = True
> >> allEqual (x1:x2:xs) = (x1 == x2) && allEqual xs
> >
> > What does this function do for "allEqual [1, 1, 2]" ?
> >
> > Antoine
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list