[Haskell-cafe] foldr1 min [(maxBound::Int)%1,1 % 2]

Cale Gibbard cgibbard at gmail.com
Wed Apr 13 09:31:44 EDT 2005


Hmm...
let a = (maxBound :: Int)%1 in 1 < a && a < 1/2 
 == True

>From the Ord instance for Ratio a
(x:%y) <  (x':%y')  =  x * y' <  x' * y

So the comparison for 1 < a looks like
1 * 1 < (maxBound :: Int) * 1
which is true.
And the comparison for a < 1/2 looks like
(maxBound :: Int) * 2 < 1 * 1
==> -2 < 1
which is again true!

If you want well-behaved rationals, I suppose you have to use Ratio Integer.

Hope this helps,
 - Cale

On 4/13/05, Bo Herlin <bo at gcab.net> wrote:
> Hi
> 
> How come
> 
>  > foldr1 min [(maxBound::Int) % 1,1 % 2]
> 2147483647 % 1
> 
> but
> 
>  > foldr1 min [2147483647 % 1,1 % 2]
> 1 % 2
> 
> Why???
> 
> /Bo Herlin
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list