[Haskell-cafe] A question about stack overflow

Neil Mitchell ndmitchell at gmail.com
Tue Jun 27 04:52:35 EDT 2006


Hi,

>   mymax []     = undefined
>   mymax (x:xs) = f x xs
>       where
>         f x [] = x
>         f x (y:ys) | y > x     = f y ys
>                    | otherwise = f x ys

Or if you don't want to go for a fold next, in a style more similar to
the original:

maximum [] = undefined
maximum [x] = x
maximum (a:b:xs) = maximum (max a b : xs)

Thanks

Neil


More information about the Haskell-Cafe mailing list