[Haskell-beginners] The numeric type stack

Mike Meyer mwm at mired.org
Fri Dec 30 00:04:26 CET 2011


 On Thu, 29 Dec 2011 04:49:53 -0500
Brandon Allbery <allbery.b at gmail.com> wrote:
> 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;

Yup. that's what I did.

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

Not an option, because div doesn't round, it truncates. Figuring out
whether to add one to get it to round would be a lot messier than just
using fromIntegral.

The other half of this is that one of the two values is computed from
constants in the code. So the code works if I don't coerce it. But all
the computation for that value is done using floats.

Seems like a violation of POLA to me.

      <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the Beginners mailing list