int to float problem

Matthew Donadio m.p.donadio@ieee.org
Mon, 3 Mar 2003 12:10:28 -0500


>Thank does sound like a pain, but it's better than putting fromIntegral
>all over my code. Why can't Haskell unify a an expected float with an
>infered int? It seems that this would make life alot easier.

This is my biggest gripe with Haskell, at least for what I do.  The numeric class system is good, but it assumes that the sub-classes are distict, where in fact integers are a proper subset of reals, which are a proper subset of complex numbers.

Personally, I would like to see module level explicit coersion, similar to the way the default numeric type is handled.  Something like:

> module Blah where

> coerce Int to Double
> in mean with fromInt

> mean :: [Double] -> Double
> mean x = sum x / length x

So, if the typesystem infers a Double, but finds an Int, the function would be rewritten as if it had been specified as

> mean x = sum x / (fromInt.length) x

If you want a global declaration then you could specify

> coerce Int to Double
> with fromInt

--Matthew Donadio (m.p.donadio@ieee.org)