haskell-cafe@haskell.org
[Top] [All Lists]

[Haskell-cafe] Re: Some clarity please!

Subject: [Haskell-cafe] Re: Some clarity please!
From: John Meacham
Date: Tue, 22 Apr 2008 21:41:33 -0700
On Tue, Apr 22, 2008 at 05:28:27PM +0000, Michael Karcher wrote:
> I am quite late to join this thread, but as I just read the thread
> about Conal's AddBounds where he had a very valid point for
> implementing min/max without resorting to <= or compare:
> 
> min [] ys = []
> min xs [] = []
> min (x:xs) (y:ys)
>  | cmp == LT = (x:xs)
>  | cmp == GT = (y:ys)
>  | cmp == EQ = x:min xs ys
>     where cmp = compare x y
> 
> This is a properly lazy implementation for min (the one in GHC's
> prelude is not), as it is able to calculate (take 5 $ min [1,2..]
> [1,2..]). This is not possible if min has to wait for compare or <= to
> compare the full lists before returning the head.

In addition, you need special min and max functions to implement IEEE
floating point properly. Of course, floating point is odd in general,
but we should be correct when we can.

        John

-- 
John Meacham - ârepetae.netâjohnâ
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>