[Haskell-beginners] maximum: stack overflow?

Chaddaï Fouché chaddai.fouche at gmail.com
Fri Mar 13 04:09:08 EDT 2009


On Fri, Mar 13, 2009 at 6:05 AM, Roland Zumkeller
<roland.zumkeller at gmail.com> wrote:
> 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:

The case where max is not strict seldom happen and anyway in those
cases foldr1 would be more appropriate than foldl1 (which won't allow
fast termination, though a non-strict max may save you from stack
overflow)...
Note that with -O or -O2 you may have a specialization of maximum to
foldl1' if you're working on Int or Integer or ...

I guess the report really dropped the ball on this one with its
failure to settle on either lazyness or strictness.

-- 
Jedaï


More information about the Beginners mailing list