Lazy minimum

David Menendez dave at
Wed Nov 19 23:38:07 EST 2008

On Wed, Nov 19, 2008 at 8:06 PM, Dave Bayer <bayer at> wrote:

> What I'm wondering, however, is if there is a way to code "minimum"
> efficiently in general,
>> minimum :: Ord a => [a] -> a
> where one knows absolutely nothing further about the type "a", but one
> believes that lazy evaluation will run afoul of the above issue.
> It would seem that this would require compiler support, allowing code to
> access approximations to lazy data generalizing the head of a lazy list. I'm
> reminded of working with power series by working mod x^n for various n.
> Here, I'd like a bounded version of "compare", that returned EQ for data
> that agreed to a specified lazy evaluation depth.
> Did I miss that class? Is there a construct in GHC that would allow me to
> write "minimum" efficiently for lazy data?

One possibility would be to add minimum and maximum to Ord with the
appropriate default definitions, similar to Monoid's mconcat.

Dave Menendez <dave at>

More information about the Glasgow-haskell-users mailing list