[Haskell-cafe] Mixed-type arithmetic, or type coercion

Henk-Jan van Tuyl hjgtuyl at chello.nl
Tue Mar 13 16:53:54 EDT 2007


On Tue, 13 Mar 2007 21:41:00 +0100, Dave Hinton <beakerchu at googlemail.com>
wrote:

> how do I coerce a value from being an Int to being a Double?
>

> calc :: Int -> Double -> Double
> calc count weight = count * weight
>

Use:
    calc count weight = fromIntegral count * weight

If you want an Int result, use:
    calc count weight = count * round weight

-- 
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://Van.Tuyl.eu/
--

Using Opera's revolutionary e-mail client:
https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433



More information about the Haskell-Cafe mailing list