prelude-safeenum-0.1.1.3: A redefinition of the Prelude's Enum class in order to render it safe.
Copyright2012--2021 wren gayle romano
LicenseBSD3
Maintainerwren@cpan.org
Stabilityprovisional
PortabilityHaskell98 + CPP + GeneralizedNewtypeDeriving
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Number.CalkinWilf

Description

Enumerate the rationals in Calkin--Wilf order. That is, when we give enumeration a well-specified meaning (as Prelude.SafeEnum does) this renders instances for Ratio problematic. Ratio instances can be provided so long as the base type is integral and enumerable; but they must be done in an obscure order that does not coincide with the Ord instance for Ratio. Since this is not what people may expect, we only provide an instance for the newtype CalkinWilf, not for Ratio itself.

Synopsis

Documentation

newtype CalkinWilf a Source #

Enumerate the rationals in Calkin--Wilf order. The enumeration is symmetric about zero, ensuring that all the negative rationals come before zero and all the positive rationals come after zero.

BUG: while the succeeds, precedes, toEnum, and fromEnum methods are correct, they are horribly inefficient. This can be rectified (or at least mitigated), but this remains to be done.

Constructors

CalkinWilf (Ratio a) 

Instances

Instances details
Integral a => Enum (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Eq a => Eq (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Methods

(==) :: CalkinWilf a -> CalkinWilf a -> Bool #

(/=) :: CalkinWilf a -> CalkinWilf a -> Bool #

Integral a => Fractional (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => Num (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => Ord (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

(Integral a, Read a) => Read (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => Real (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => RealFrac (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Methods

properFraction :: Integral b => CalkinWilf a -> (b, CalkinWilf a) #

truncate :: Integral b => CalkinWilf a -> b #

round :: Integral b => CalkinWilf a -> b #

ceiling :: Integral b => CalkinWilf a -> b #

floor :: Integral b => CalkinWilf a -> b #

Show a => Show (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => Enum (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => DownwardEnum (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

Integral a => UpwardEnum (CalkinWilf a) Source # 
Instance details

Defined in Data.Number.CalkinWilf

unCalkinWilf :: CalkinWilf a -> Ratio a Source #

Return the underlying Ratio. Not using record syntax to define this in order to pretty up the derived Show instance.