Neil Mitchell wrote:
> 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)

It even reproduces the stack overflow, though for a different reason.
Better write it this way:

maximum [] = undefined
maximum [x] = x
maximum (a:b:xs) = let m = max a b in m `seq` maximum (m : xs)


Udo.
-- 
"The condition of man is already close to satiety and arrogance, and
there is danger of destruction of everything in existence."
        -- a Brahmin to Onesicritus, 327 BC,
           reported in Strabo's Geography

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to