HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulenumeric-prelude-0.4.4Haskell98

Algebra.ToRational

  • 1 class
  • 1 value
classclass (C a, C a, Ord a) => C a where
#

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

Methods

Instances19C, …
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Int16Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Int32Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Int64Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Int8Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Word16Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Word32Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Word64Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C Word8Defined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C WordDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C TDefined in numeric-prelude-0.4.4 · Number.Peano
  • Real a => C (T a)Defined in numeric-prelude-0.4.4 · MathObj.Wrapper.Haskell98
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · MathObj.Wrapper.NumericPrelude
  • (Ord a, C a) => C (T a)Defined in numeric-prelude-0.4.4 · Number.NonNegative · orphan
  • (C a, C a) => C (T a)Defined in numeric-prelude-0.4.4 · Algebra.ToInteger · orphan
  • (C a, C a) => C (T a)Defined in numeric-prelude-0.4.4 · Number.NonNegativeChunky
valuerealToField :: (C a, C b) => a -> b
#

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.