Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Integral classes
Synopsis
- class Distributive a => Integral a where
- class ToIntegral a b where
- toIntegral :: a -> b
- class FromIntegral a b where
- fromIntegral :: b -> a
- 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 of `type FromInteger a = FromIntegral a Integer` doesn't work well with type defaulting; hence the need for a separate class.
fromInteger :: Integer -> a Source #
Instances
(^) :: Divisive a => a -> Int -> a infixr 8 Source #
raise a number to an Int
power
Note: This differs from (^) found in prelude which is a partial function (it errors on negative integrals). This monomorphic version is provided to help reduce ambiguous type noise in common usages of this sign.
>>>
2 ^ 3
8.0
>>>
2 ^ (-2)
0.25