[Haskell-beginners] The numeric type stack

Brandon Allbery allbery.b at gmail.com
Thu Dec 29 10:49:53 CET 2011


On Thu, Dec 29, 2011 at 00:33, Mike Meyer <mwm at mired.org> wrote:

> So, is there a reasonable way to get the value of two Integral types
> divided by each other and rounded? How about one integral type and one
> RealFrac? I know I can get it truncated towards either 0 or negative
> infinity, but that's not what I want here.
>

You have two options:

(1) use fromIntegral to coerce an Integral value to a RealFrac;

(2) use (div) (division on Integrals) instead of (/).

Which to use depends on what you're planning to do with the result.  In
this case, I'd probably use (/) and (fromIntegral).

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111229/cd48d6bd/attachment.htm>


More information about the Beginners mailing list