module Plankton.Integral
( Integral(..)
, ToInteger(..)
, FromInteger(..)
, fromIntegral
) where
import Plankton.Ring
import qualified Protolude as P
import Protolude (Double, Float, Int, Integer, (.), fst, snd)
class (Ring a) =>
Integral a where
infixl 7 `div`, `mod`
div :: a -> a -> a
div a1 a2 = fst (divMod a1 a2)
mod :: a -> a -> a
mod a1 a2 = snd (divMod a1 a2)
divMod :: a -> a -> (a, a)
instance Integral Int where
divMod = P.divMod
instance Integral Integer where
divMod = P.divMod
class ToInteger a where
toInteger :: a -> Integer
class FromInteger a where
fromInteger :: Integer -> a
fromIntegral :: (ToInteger a, FromInteger b) => a -> b
fromIntegral = fromInteger . toInteger
instance FromInteger Double where
fromInteger = P.fromInteger
instance FromInteger Float where
fromInteger = P.fromInteger
instance FromInteger Int where
fromInteger = P.fromInteger
instance FromInteger Integer where
fromInteger = P.fromInteger
instance ToInteger Int where
toInteger = P.toInteger
instance ToInteger Integer where
toInteger = P.toInteger