Revised numerical prelude, version 0.02
Wed, 14 Feb 2001 17:20:11 -0500
On Wed, Feb 14, 2001 at 09:53:16PM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> Tue, 13 Feb 2001 18:32:21 -0500, Dylan Thurston <email@example.com> pisze:
> > Here's a revision of the numerical prelude.
> I like it!
I'd like to start using something like this in my programs. What are
the chances that the usability issues will be addressed? (The main
one is all the fromInteger's, I think.)
> > > class (Real a, Floating a) => RealFrac a where
> > > -- lifted directly from Haskell 98 Prelude
> > > properFraction :: (Integral b) => a -> (b,a)
> > > truncate, round :: (Integral b) => a -> b
> > > ceiling, floor :: (Integral b) => a -> b
> These should be SmallIntegral.
It could be either one, since they produce the type on output (it
calls fromInteger). I changed it, on the theory that it might be less
confusing. But it should inherit from SmallReal. (Oh, except then
RealFloat inherits from SmallReal, which it shouldn't have to. Gah.)
> > For an instance of RealIntegral a, it is expected that a `quot` b
> > will round towards minus infinity and a `div` b will round towards 0.
> The opposite.
> > > class (Real a) => SmallReal a where
> > > toRational :: a -> Rational
> > > class (SmallReal a, RealIntegral a) => SmallIntegral a where
> > > toInteger :: a -> Integer
> I find names of these classes unclear: Integer is not small integral,
> it's big integral (as opposed to Int)! :-)
I agree, but I couldn't think of anything better. I think this end of
the heirarchy (that inherits from Real) could use some more work.
RealIntegral and SmallIntegral could possibly be merged, except that
it violates the principle of not combining semantically disparate
operations in a single class.