module Algebra.ToInteger where
import qualified Number.Ratio as Ratio
import qualified Algebra.ToRational as ToRational
import qualified Algebra.Field as Field
import qualified Algebra.PrincipalIdealDomain as PID
import qualified Algebra.RealIntegral as RealIntegral
import qualified Algebra.Ring as Ring
import Number.Ratio (T((:%)), )
import Algebra.Field ((^-), )
import Algebra.Ring ((^), fromInteger, )
import qualified Prelude as P
import PreludeBase
import Prelude(Int,Integer)
class (ToRational.C a, RealIntegral.C a) => C a where
toInteger :: a -> Integer
fromIntegral :: (C a, Ring.C b) => a -> b
fromIntegral = fromInteger . toInteger
instance C Integer where
toInteger = id
instance C Int where
toInteger = P.toInteger
instance (C a, PID.C a) => ToRational.C (Ratio.T a) where
toRational (x:%y) = toInteger x :% toInteger y
ringPower :: (Ring.C a, C b) => b -> a -> a
ringPower exponent basis = basis ^ toInteger exponent
fieldPower :: (Field.C a, C b) => b -> a -> a
fieldPower exponent basis = basis ^- toInteger exponent