[Haskell-cafe] Re: Some clarity please!
john at repetae.net
Wed Apr 23 00:41:33 EDT 2008
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 Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-Cafe