[Haskell-beginners] maximum: stack overflow?
Roland Zumkeller
roland.zumkeller at gmail.com
Fri Mar 13 01:05:48 EDT 2009
Hi Alex,
On Fri, Mar 13, 2009 at 12:43 AM, Alexander Dunlap
<alexander.dunlap at gmail.com> wrote:
> Isn't maximum always (semantically) strict anyway? I.e.
>
> maximum [1,2,undefined] = undefined
If max is (semantically) strict, then so is maximum.
On the other hand, both may be non-strict:
> data Switch = Off | On deriving (Eq, Show)
> instance Ord Switch where
> On <= Off = False
> _ <= _ = True
> max _ On = On
> max a Off = a
*Main> maximum [undefined,Off,On]
On
*Main> foldl1' max [undefined,Off,On]
*** Exception: Prelude.undefined
Best,
Roland
--
http://roland.zumkeller.googlepages.com/
More information about the Beginners
mailing list