numeric-prelude-0.3: An experimental alternative hierarchy of numeric type classes




class (C a, C a, Ord a) => C a whereSource

This class allows lossless conversion from any representation of a rational to the fixed Rational type. "Lossless" means - don't do any rounding. For rounding see Algebra.RealRing. With the instances for Float and Double we acknowledge that these types actually represent rationals rather than (approximated) real numbers. However, this contradicts to the Algebra.Transcendental class.

Laws that must be satisfied by instances:

  fromRational' . toRational === id


toRational :: a -> RationalSource

Lossless conversion from any representation of a rational to Rational


C Double 
C Float 
C Int 
C Int8 
C Int16 
C Int32 
C Int64 
C Integer 
C Word 
C Word8 
C Word16 
C Word32 
C Word64 
C T 
(Ord a, C a) => C (T a) 
(C a, C a) => C (T a) 
Real a => C (T a) 
C a => C (T a) 
(C a, C a) => C (T a) 

realToField :: (C a, C b) => a -> bSource

It should hold

 realToField = fromRational' . toRational

but it should be much more efficient for particular pairs of types, such as converting Float to Double. This achieved by optimizer rules.