
13 Nov
2001
13 Nov
'01
9:07 a.m.
Jesper Louis Andersen
This problem has had my attention for a while now. I hope someone would like to help me out on the problem.
I have a simple average function defined as:
mean :: (Fractional a) => [a] -> a mean l = (sum l)/ fromIntegral (length l)
due to the absence of subtyping, things like this will work only if you don't precise the type, keeping class constraints. -- length2 :: Num a => [b] -> a length2 [] = 0 length2 (x:xs) = 1 + length2 xs -- mean :: Fractional a => [a] -> a mean l = sum l / length2 l m = (mean [1,0,0] :: Rational, mean [1,0,0] :: Double) gives 1%3 and 0.333333 (thanks to pad for pinpointing the haskell solution, merd solution is http://merd.sf.net/inference.txt)