
13 Mar
2007
13 Mar
'07
4:51 p.m.
Hi
Arithmetic operators in haskell appear to require their operands to have the same type. How can I do arithmetic between operands of different types?
You probably don't want to.
Alternatively, how do I coerce a value from being an Int to being a Double?
You ask Hoogle: http://haskell.org/hoogle/?q=Integer+-%3E+Double The answer is fromInteger/toInteger as required.
calc :: Int -> Double -> Double calc count weight = fromInteger (toInteger count) * weight
toInteger promotes the Int to an Integer, fromInteger then converts that to a Double. Thanks Neil