numhask-0.11.1.0: A numeric class hierarchy.
Safe HaskellSafe-Inferred
LanguageGHC2021

NumHask.Data.Integral

Description

Integral classes

Synopsis

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)

Minimal complete definition

divMod, quotRem

Methods

div :: a -> a -> a infixl 7 Source #

mod :: a -> a -> a infixl 7 Source #

divMod :: a -> a -> (a, a) Source #

quot :: a -> a -> a Source #

rem :: a -> a -> a Source #

quotRem :: a -> a -> (a, a) Source #

Instances

Instances details
Integral Int16 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Int32 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Int64 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Int8 Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

div :: Int8 -> Int8 -> Int8 Source #

mod :: Int8 -> Int8 -> Int8 Source #

divMod :: Int8 -> Int8 -> (Int8, Int8) Source #

quot :: Int8 -> Int8 -> Int8 Source #

rem :: Int8 -> Int8 -> Int8 Source #

quotRem :: Int8 -> Int8 -> (Int8, Int8) Source #

Integral Word16 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Word32 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Word64 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Word8 Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Integer Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Natural Source # 
Instance details

Defined in NumHask.Data.Integral

Integral Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

div :: Int -> Int -> Int Source #

mod :: Int -> Int -> Int Source #

divMod :: Int -> Int -> (Int, Int) Source #

quot :: Int -> Int -> Int Source #

rem :: Int -> Int -> Int Source #

quotRem :: Int -> Int -> (Int, Int) Source #

Integral Word Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

div :: Word -> Word -> Word Source #

mod :: Word -> Word -> Word Source #

divMod :: Word -> Word -> (Word, Word) Source #

quot :: Word -> Word -> Word Source #

rem :: Word -> Word -> Word Source #

quotRem :: Word -> Word -> (Word, Word) Source #

Integral b => Integral (a -> b) Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

div :: (a -> b) -> (a -> b) -> a -> b Source #

mod :: (a -> b) -> (a -> b) -> a -> b Source #

divMod :: (a -> b) -> (a -> b) -> (a -> b, a -> b) Source #

quot :: (a -> b) -> (a -> b) -> a -> b Source #

rem :: (a -> b) -> (a -> b) -> a -> b Source #

quotRem :: (a -> b) -> (a -> b) -> (a -> b, a -> b) Source #

class ToIntegral a b where Source #

toIntegral is kept separate from Integral to help with compatability issues.

toIntegral a == a

Methods

toIntegral :: a -> b Source #

Instances

Instances details
ToIntegral Int16 Int16 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int16 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int16 Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int16 -> Int Source #

ToIntegral Int32 Int32 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int32 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int32 Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int32 -> Int Source #

ToIntegral Int64 Int64 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int64 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int64 Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int64 -> Int Source #

ToIntegral Int8 Int8 Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int8 -> Int8 Source #

ToIntegral Int8 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int8 Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int8 -> Int Source #

ToIntegral Word16 Word16 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word16 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word16 Int Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word32 Word32 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word32 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word32 Int Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word64 Word64 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word64 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word64 Int Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word8 Word8 Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word8 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word8 Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Word8 -> Int Source #

ToIntegral Integer Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Integer Int Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Natural Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Natural Natural Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Natural Int Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Int Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Int -> Int Source #

ToIntegral Word Integer Source # 
Instance details

Defined in NumHask.Data.Integral

ToIntegral Word Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Word -> Int Source #

ToIntegral Word Word Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

toIntegral :: Word -> Word Source #

type ToInt a = ToIntegral a Int Source #

Convert to an Int

class FromIntegral a b where Source #

Polymorphic version of fromInteger

fromIntegral a == a

Methods

fromIntegral :: b -> a Source #

Instances

Instances details
FromIntegral Int16 Int16 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int16 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int16 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int32 Int32 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int32 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int32 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int64 Int64 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int64 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int64 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int8 Int8 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int8 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int8 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word16 Word16 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word16 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word16 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word32 Word32 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word32 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word32 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word64 Word64 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word64 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word64 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word8 Word8 Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word8 Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word8 Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Integer Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Integer Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Natural Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Natural Natural Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Natural Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Double Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Double Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Float Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Float Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Int Int Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

fromIntegral :: Int -> Int Source #

FromIntegral Word Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromIntegral Word Word Source # 
Instance details

Defined in NumHask.Data.Integral

(Additive a, FromIntegral a b) => FromIntegral (Complex a) b Source # 
Instance details

Defined in NumHask.Data.Complex

Methods

fromIntegral :: b -> Complex a Source #

(FromIntegral a b, Multiplicative a) => FromIntegral (Ratio a) b Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

fromIntegral :: b -> Ratio a Source #

FromIntegral a b => FromIntegral (c -> a) b Source # 
Instance details

Defined in NumHask.Data.Integral

Methods

fromIntegral :: b -> c -> a Source #

type FromInt a = FromIntegral a Int Source #

Convert from an Int

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 form C 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.

Methods

fromInteger :: Integer -> a Source #

Instances

Instances details
FromInteger Int16 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Int32 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Int64 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Int8 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Word16 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Word32 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Word64 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Word8 Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Integer Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Natural Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Double Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Float Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Int Source # 
Instance details

Defined in NumHask.Data.Integral

FromInteger Word Source # 
Instance details

Defined in NumHask.Data.Integral

even :: (Eq a, Integral a) => a -> Bool Source #

>>> even 2
True

odd :: (Eq a, Integral a) => a -> Bool Source #

>>> odd 3
True

(^^) :: (Ord b, Divisive a, Subtractive b, Integral b) => a -> b -> a infixr 8 Source #

raise a number to an Integral power

>>> 2 ^^ 3
8.0
>>> 2 ^^ (-2)
0.25

(^) :: 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 is a monomorphic version of (^^) provided to help reduce ambiguous type noise in common usages.

>>> 2 ^ 3
8.0
>>> 2 ^ (-2)
0.25