[Haskell-cafe] A question about stack overflow
Udo Stenzel
u.stenzel at web.de
Tue Jun 27 06:11:36 EDT 2006
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060627/567f2066/attachment.bin
More information about the Haskell-Cafe
mailing list