Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- Module      :  GHC.Num-- Copyright   :  (c) The University of Glasgow 1994-2002-- License     :  see libraries/base/LICENSE---- Maintainer  :  cvs-ghc@haskell.org-- Stability   :  internal-- Portability :  non-portable (GHC Extensions)---- The 'Num' class and the 'Integer' type.-------------------------------------------------------------------------------moduleGHC.Num(moduleGHC.Num,moduleGHC.Num.Integer,moduleGHC.Num.Natural-- reexported for backward compatibility,moduleGHC.Natural,moduleGHC.Integer)where#include "MachDeps.h"importqualifiedGHC.NaturalimportqualifiedGHC.IntegerimportGHC.BaseimportGHC.Num.IntegerimportGHC.Num.Naturalinfixl7*infixl6+,-default()-- Double isn't available yet,-- and we shouldn't be using defaults anyway-- | Basic numeric class.---- The Haskell Report defines no laws for 'Num'. However, @('+')@ and @('*')@ are-- customarily expected to define a ring and have the following properties:---- [__Associativity of @('+')@__]: @(x + y) + z@ = @x + (y + z)@-- [__Commutativity of @('+')@__]: @x + y@ = @y + x@-- [__@'fromInteger' 0@ is the additive identity__]: @x + fromInteger 0@ = @x@-- [__'negate' gives the additive inverse__]: @x + negate x@ = @fromInteger 0@-- [__Associativity of @('*')@__]: @(x * y) * z@ = @x * (y * z)@-- [__@'fromInteger' 1@ is the multiplicative identity__]:-- @x * fromInteger 1@ = @x@ and @fromInteger 1 * x@ = @x@-- [__Distributivity of @('*')@ with respect to @('+')@__]:-- @a * (b + c)@ = @(a * b) + (a * c)@ and @(b + c) * a@ = @(b * a) + (c * a)@-- [__Coherence with 'toInteger'__]: if the type also implements 'GHC.Real.Integral', then-- 'fromInteger' is a left inverse for 'GHC.Real.toInteger', i.e. @fromInteger (toInteger i) == i@---- Note that it /isn't/ customarily expected that a type instance of both 'Num'-- and 'Ord' implement an ordered ring. Indeed, in @base@ only 'Integer' and-- 'Data.Ratio.Rational' do.classNumawhere{-# MINIMAL(+),(*),abs,signum,fromInteger,(negate|(-))#-}(+),(-),(*)::a->a->a-- | Unary negation.negate::a->a-- | Absolute value.abs::a->a-- | Sign of a number.-- The functions 'abs' and 'signum' should satisfy the law:---- > abs x * signum x == x---- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero)-- or @1@ (positive).signum::a->a-- | Conversion from an 'Integer'.-- An integer literal represents the application of the function-- 'fromInteger' to the appropriate value of type 'Integer',-- so such literals have type @('Num' a) => a@.fromInteger::Integer->a{-# INLINE(-)#-}{-# INLINEnegate#-}ax-ay=axa -> a -> aforall a. Num a => a -> a -> a+a -> aforall a. Num a => a -> anegateaynegateax=a0a -> a -> aforall a. Num a => a -> a -> a-ax-- | the same as @'flip' ('-')@.---- Because @-@ is treated specially in the Haskell grammar,-- @(-@ /e/@)@ is not a section, but an application of prefix negation.-- However, @('subtract'@ /exp/@)@ is equivalent to the disallowed section.{-# INLINEsubtract#-}subtract::(Numa)=>a->a->asubtract :: forall a. Num a => a -> a -> asubtractaxay=aya -> a -> aforall a. Num a => a -> a -> a-ax-- | @since 2.01instanceNumIntwhereI#Int#x+ :: Int -> Int -> Int+I#Int#y=Int# -> IntI#(Int#xInt# -> Int# -> Int#+#Int#y)I#Int#x- :: Int -> Int -> Int-I#Int#y=Int# -> IntI#(Int#xInt# -> Int# -> Int#-#Int#y)negate :: Int -> Intnegate(I#Int#x)=Int# -> IntI#(Int# -> Int#negateInt#Int#x)I#Int#x* :: Int -> Int -> Int*I#Int#y=Int# -> IntI#(Int#xInt# -> Int# -> Int#*#Int#y)abs :: Int -> IntabsIntn=ifIntnInt -> Int -> Bool`geInt`Int0thenIntnelseInt -> Intforall a. Num a => a -> anegateIntnsignum :: Int -> IntsignumIntn|IntnInt -> Int -> Bool`ltInt`Int0=Int -> Intforall a. Num a => a -> anegateInt1|IntnInt -> Int -> Bool`eqInt`Int0=Int0|Boolotherwise=Int1fromInteger :: Integer -> IntfromIntegerIntegeri=Int# -> IntI#(Integer -> Int#integerToInt#Integeri)-- | @since 2.01instanceNumWordwhere(W#Word#x#)+ :: Word -> Word -> Word+(W#Word#y#)=Word# -> WordW#(Word#x#Word# -> Word# -> Word#`plusWord#`Word#y#)(W#Word#x#)- :: Word -> Word -> Word-(W#Word#y#)=Word# -> WordW#(Word#x#Word# -> Word# -> Word#`minusWord#`Word#y#)(W#Word#x#)* :: Word -> Word -> Word*(W#Word#y#)=Word# -> WordW#(Word#x#Word# -> Word# -> Word#`timesWord#`Word#y#)negate :: Word -> Wordnegate(W#Word#x#)=Word# -> WordW#(Int# -> Word#int2Word#(Int# -> Int#negateInt#(Word# -> Int#word2Int#Word#x#)))abs :: Word -> WordabsWordx=Wordxsignum :: Word -> WordsignumWord0=Word0signumWord_=Word1fromInteger :: Integer -> WordfromIntegerIntegeri=Word# -> WordW#(Integer -> Word#integerToWord#Integeri)-- | @since 2.01instanceNumIntegerwhere+ :: Integer -> Integer -> Integer(+)=Integer -> Integer -> IntegerintegerAdd(-)=Integer -> Integer -> IntegerintegerSub* :: Integer -> Integer -> Integer(*)=Integer -> Integer -> IntegerintegerMulnegate :: Integer -> Integernegate=Integer -> IntegerintegerNegatefromInteger :: Integer -> IntegerfromIntegerIntegeri=Integeriabs :: Integer -> Integerabs=Integer -> IntegerintegerAbssignum :: Integer -> Integersignum=Integer -> IntegerintegerSignum-- | Note that `Natural`'s 'Num' instance isn't a ring: no element but 0 has an-- additive inverse. It is a semiring though.---- @since 4.8.0.0instanceNumNaturalwhere+ :: Natural -> Natural -> Natural(+)=Natural -> Natural -> NaturalnaturalAdd(-)=Natural -> Natural -> NaturalnaturalSubThrow* :: Natural -> Natural -> Natural(*)=Natural -> Natural -> NaturalnaturalMulnegate :: Natural -> Naturalnegate=Natural -> NaturalnaturalNegatefromInteger :: Integer -> NaturalfromIntegerIntegeri=Integer -> NaturalintegerToNaturalThrowIntegeriabs :: Natural -> Naturalabs=Natural -> Naturalforall a. a -> aidsignum :: Natural -> Naturalsignum=Natural -> NaturalnaturalSignum{-# DEPRECATEDquotRemInteger"Use integerQuotRem# instead"#-}quotRemInteger::Integer->Integer->(#Integer,Integer#)quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)quotRemInteger=Integer -> Integer -> (# Integer, Integer #)integerQuotRem#

[8]ページ先頭

©2009-2025 Movatter.jp