Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Integral classes
Synopsis
- class Distributive a => Integral a where
- class ToIntegral a b where
- toIntegral :: a -> b
- type ToInt a = ToIntegral a Int
- class FromIntegral a b where
- fromIntegral :: b -> a
- type FromInt a = FromIntegral a Int
- class FromInteger a where
- fromInteger :: Integer -> a
- even :: (Eq a, Integral a) => a -> Bool
- odd :: (Eq a, Integral a) => a -> Bool
- (^^) :: (Ord b, Divisive a, Subtractive b, Integral b) => a -> b -> a
- (^) :: Divisive a => a -> Int -> a
Documentation
class Distributive a => Integral a where Source #
An Integral is anything that satisfies the law:
\a b -> b == zero || b * (a `div` b) + (a `mod` b) == a
>>>
3 `divMod` 2
(1,1)
>>>
(-3) `divMod` 2
(-2,1)
>>>
(-3) `quotRem` 2
(-1,-1)
div :: a -> a -> a infixl 7 Source #
mod :: a -> a -> a infixl 7 Source #
Instances
class ToIntegral a b where Source #
toIntegral is kept separate from Integral to help with compatability issues.
toIntegral a == a
toIntegral :: a -> b Source #
Instances
class FromIntegral a b where Source #
Polymorphic version of fromInteger
fromIntegral a == a
fromIntegral :: b -> a Source #
Instances
class FromInteger a where Source #
fromInteger
is special in two ways:
- numeric integral literals (like "42") are interpreted specifically as "fromInteger (42 :: GHC.Num.Integer)". The prelude version is used as default (or whatever fromInteger is in scope if RebindableSyntax is set).
- The default rules in haskell2010 specify that constraints on
fromInteger
need to be in a formC v
, where v is a Num or a subclass of Num.
So a type synonym such as type FromInteger a = FromIntegral a Integer
doesn't work well with type defaulting; hence the need for a separate class.
fromInteger :: Integer -> a Source #