Having contraints like 'Fractional Int => IO ()'

Ashley Yakeley ashley@semantic.org
Tue, 13 Nov 2001 01:51:14 -0800

At 2001-11-12 18:06, Jesper Louis Andersen wrote:

>mean            :: (Fractional a) => [a] -> a
>mean l          = (sum l)/ fromIntegral (length l)
>Which imposes a type constraint (of course). My problem is, that i
>cannot ``let go'' of this constraint. 

>main		:: Fractional Int => IO ()

It sounds like you're trying to use your 'mean' function on Ints. Int is 
not a Fractional type (unless you make it one), and so '/' isn't defined 
on it.

What's "mean [3::Int,4::Int]"? It can't be "3.5::Int" because 3.5 is not 
an integer and so not an Int.

Ashley Yakeley, Seattle WA