Safe Haskell | None |
---|---|
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:
b == zero || b * (a `div` b) + (a `mod` b) == a
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 #
default toIntegral :: a ~ b => a -> b Source #
Instances
class FromIntegral a b where Source #
Polymorphic version of fromInteger
fromIntegral a == a
fromIntegral :: b -> a Source #
default fromIntegral :: a ~ b => 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 #