Copyright | (c) Eric Crockett 2011-2017 Chris Peikert 2011-2017 |
---|---|
License | GPL-3 |
Maintainer | ecrockett0@email.com |
Stability | experimental |
Portability | POSIX \( \def\Z{\mathbb{Z}} \) \( \def\C{\mathbb{C}} \) |
Safe Haskell | None |
Language | Haskell2010 |
A substitute for the Prelude that is more suitable for Lol. This module exports most of the Numeric Prelude and other frequently used modules, plus some low-level classes, missing instances, and assorted utility functions.
Synopsis
- class Enumerable a where
- values :: [a]
- class (ToInteger (ModRep a), Additive a) => Mod a where
- class (Additive a, Additive b) => Subgroup a b where
- fromSubgroup :: a -> b
- class Reduce a b where
- reduce :: a -> b
- type family LiftOf b
- type Lift b a = (Lift' b, LiftOf b ~ a)
- class Reduce (LiftOf b) b => Lift' b where
- class (Additive a, Additive b) => Rescale a b where
- rescale :: a -> b
- class (Field src, Field tgt) => Encode src tgt where
- lsdToMSD :: (src, tgt)
- msdToLSD :: Encode src tgt => (src, tgt)
- type family CharOf fp :: k
- type Matrix a = T a
- type Polynomial a = T a
- type PID a = C a
- type RealIntegral a = C a
- type Absolute a = C a
- type ToInteger a = C a
- type OrdFloat a = (Ord a, Transcendental a)
- type RealTranscendental a = C a
- type Transcendental a = C a
- type Algebraic a = C a
- type RealField a = C a
- type RealRing a = C a
- type Field a = C a
- type ToRational a = C a
- type IntegralDomain a = C a
- type Module a v = C a v
- type Ring a = C a
- type Additive a = C a
- type ZeroTestable a = C a
- max :: Ord a => a -> a -> a
- min :: Ord a => a -> a -> a
- abs :: Absolute a => a -> a
- realToField :: (Field b, ToRational a) => a -> b
- (^) :: forall a i. (Ring a, ToInteger i) => a -> i -> a
- modinv :: (PID i, Eq i) => i -> i -> Maybe i
- decomp :: (IntegralDomain z, Ord z) => [z] -> z -> [z]
- roundMult :: (RealField r, ToInteger i) => i -> r -> i
- roundScalarCentered :: (RealField r, Random r, ToInteger i, MonadRandom mon) => i -> r -> mon i
- divModCent :: IntegralDomain i => i -> i -> (i, i)
- (++) :: [a] -> [a] -> [a]
- seq :: a -> b -> b
- filter :: (a -> Bool) -> [a] -> [a]
- zip :: [a] -> [b] -> [(a, b)]
- print :: Show a => a -> IO ()
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- otherwise :: Bool
- map :: (a -> b) -> [a] -> [b]
- ($) :: (a -> b) -> a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- class Bounded a where
- class Enum a where
- succ :: a -> a
- pred :: a -> a
- toEnum :: Int -> a
- fromEnum :: a -> Int
- enumFrom :: a -> [a]
- enumFromThen :: a -> a -> [a]
- enumFromTo :: a -> a -> [a]
- enumFromThenTo :: a -> a -> a -> [a]
- class Eq a where
- class Applicative m => Monad (m :: Type -> Type) where
- class Functor (f :: Type -> Type) where
- class Eq a => Ord a where
- class Read a where
- class Show a where
- foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- length :: Foldable t => t a -> Int
- null :: Foldable t => t a -> Bool
- foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldl1 :: Foldable t => (a -> a -> a) -> t a -> a
- foldr1 :: Foldable t => (a -> a -> a) -> t a -> a
- maximum :: (Foldable t, Ord a) => t a -> a
- minimum :: (Foldable t, Ord a) => t a -> a
- elem :: (Foldable t, Eq a) => a -> t a -> Bool
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- data Bool
- data Char
- data Double
- data Float
- data Int
- data Integer
- data Maybe a
- data Ordering
- data IO a
- data Either a b
- type FilePath = String
- error :: HasCallStack => [Char] -> a
- type String = [Char]
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- const :: a -> b -> a
- (.) :: (b -> c) -> (a -> b) -> a -> c
- id :: a -> a
- type ShowS = String -> String
- read :: Read a => String -> a
- readIO :: Read a => String -> IO a
- readLn :: Read a => IO a
- appendFile :: FilePath -> String -> IO ()
- writeFile :: FilePath -> String -> IO ()
- readFile :: FilePath -> IO String
- interact :: (String -> String) -> IO ()
- getContents :: IO String
- getLine :: IO String
- getChar :: IO Char
- putStrLn :: String -> IO ()
- putStr :: String -> IO ()
- putChar :: Char -> IO ()
- ioError :: IOError -> IO a
- userError :: String -> IOError
- type IOError = IOException
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- or :: Foldable t => t Bool -> Bool
- and :: Foldable t => t Bool -> Bool
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- concat :: Foldable t => t [a] -> [a]
- unwords :: [String] -> String
- words :: String -> [String]
- unlines :: [String] -> String
- lines :: String -> [String]
- reads :: Read a => ReadS a
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- lex :: ReadS String
- readParen :: Bool -> ReadS a -> ReadS a
- type ReadS a = String -> [(a, String)]
- showParen :: Bool -> ShowS -> ShowS
- showString :: String -> ShowS
- showChar :: Char -> ShowS
- shows :: Show a => a -> ShowS
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- unzip :: [(a, b)] -> ([a], [b])
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- (!!) :: [a] -> Int -> a
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- reverse :: [a] -> [a]
- break :: (a -> Bool) -> [a] -> ([a], [a])
- span :: (a -> Bool) -> [a] -> ([a], [a])
- splitAt :: Int -> [a] -> ([a], [a])
- drop :: Int -> [a] -> [a]
- take :: Int -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- takeWhile :: (a -> Bool) -> [a] -> [a]
- cycle :: [a] -> [a]
- replicate :: Int -> a -> [a]
- repeat :: a -> [a]
- iterate :: (a -> a) -> a -> [a]
- scanr1 :: (a -> a -> a) -> [a] -> [a]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- init :: [a] -> [a]
- last :: [a] -> a
- tail :: [a] -> [a]
- head :: [a] -> a
- maybe :: b -> (a -> b) -> Maybe a -> b
- uncurry :: (a -> b -> c) -> (a, b) -> c
- curry :: ((a, b) -> c) -> a -> b -> c
- asTypeOf :: a -> a -> a
- until :: (a -> Bool) -> (a -> a) -> a -> a
- ($!) :: (a -> b) -> a -> b
- flip :: (a -> b -> c) -> b -> a -> c
- undefined :: HasCallStack => a
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- not :: Bool -> Bool
- atan2 :: C a => a -> a -> a
- approxRational :: (C a, C a) => a -> a -> Rational
- truncate :: (C a, C b) => a -> b
- round :: (C a, C b) => a -> b
- ceiling :: (C a, C b) => a -> b
- floor :: (C a, C b) => a -> b
- splitFraction :: (C a, C b) => a -> (b, a)
- fraction :: C a => a -> a
- (^?) :: C a => a -> a -> a
- pi :: C a => a
- exp :: C a => a -> a
- log :: C a => a -> a
- (**) :: C a => a -> a -> a
- logBase :: C a => a -> a -> a
- sin :: C a => a -> a
- cos :: C a => a -> a
- tan :: C a => a -> a
- asin :: C a => a -> a
- acos :: C a => a -> a
- atan :: C a => a -> a
- sinh :: C a => a -> a
- cosh :: C a => a -> a
- tanh :: C a => a -> a
- asinh :: C a => a -> a
- acosh :: C a => a -> a
- atanh :: C a => a -> a
- sqrt :: C a => a -> a
- (^/) :: C a => a -> Rational -> a
- (*>) :: C a v => a -> v -> v
- fieldPower :: (C a, C b) => b -> a -> a
- ringPower :: (C a, C b) => b -> a -> a
- fromIntegral :: (C a, C b) => a -> b
- toInteger :: C a => a -> Integer
- quotRem :: C a => a -> a -> (a, a)
- quot :: C a => a -> a -> a
- rem :: C a => a -> a -> a
- toRational :: C a => a -> Rational
- fromRational :: C a => Rational -> a
- (/) :: C a => a -> a -> a
- recip :: C a => a -> a
- fromRational' :: C a => Rational -> a
- (^-) :: C a => a -> Integer -> a
- (%) :: C a => a -> a -> T a
- numerator :: T a -> a
- denominator :: T a -> a
- type Rational = T Integer
- signum :: C a => a -> a
- extendedEuclid :: (C a, C a) => (a -> a -> (a, a)) -> a -> a -> (a, (a, a))
- euclid :: (C a, C a) => (a -> a -> a) -> a -> a -> a
- gcd :: C a => a -> a -> a
- lcm :: C a => a -> a -> a
- extendedGCD :: C a => a -> a -> (a, (a, a))
- isUnit :: C a => a -> Bool
- stdAssociate :: C a => a -> a
- stdUnit :: C a => a -> a
- stdUnitInv :: C a => a -> a
- odd :: (C a, C a) => a -> Bool
- even :: (C a, C a) => a -> Bool
- divides :: (C a, C a) => a -> a -> Bool
- divMod :: C a => a -> a -> (a, a)
- div :: C a => a -> a -> a
- mod :: C a => a -> a -> a
- product1 :: C a => [a] -> a
- product :: C a => [a] -> a
- sqr :: C a => a -> a
- (*) :: C a => a -> a -> a
- fromInteger :: C a => Integer -> a
- one :: C a => a
- isZero :: C a => a -> Bool
- sum1 :: C a => [a] -> a
- sum :: C a => [a] -> a
- subtract :: C a => a -> a -> a
- (+) :: C a => a -> a -> a
- (-) :: C a => a -> a -> a
- negate :: C a => a -> a
- zero :: C a => a
- catch :: IO a -> (IOError -> IO a) -> IO a
- ifThenElse :: Bool -> a -> a -> a
- data Int64
- data Complex a
- roundComplex :: (RealRing a, ToInteger b) => Complex a -> (b, b)
- cis :: Transcendental a => a -> Complex a
- real :: Complex a -> a
- imag :: Complex a -> a
- fromReal :: Additive a => a -> Complex a
- module Crypto.Lol.Factored
- rescaleMod :: forall a b. (Mod a, Mod b, ModRep a ~ ModRep b, Lift a (ModRep b), Ring b) => a -> b
- roundCoset :: forall zp z r. (Mod zp, z ~ ModRep zp, Lift zp z, RealField r) => zp -> r -> z
- fromJust' :: String -> Maybe a -> a
- pureT :: Applicative f => Tagged t a -> TaggedT t f a
- peelT :: Tagged t (f a) -> TaggedT t f a
- pasteT :: TaggedT t f a -> Tagged t (f a)
- withWitness :: forall n r. (SingI n => Tagged n r) -> Sing n -> r
- withWitnessT :: forall n mon r. (SingI n => TaggedT n mon r) -> Sing n -> mon r
- module Data.Functor.Trans.Tagged
- module Data.Proxy
Classes and families
class Enumerable a where Source #
Poor man's Enum
.
class (ToInteger (ModRep a), Additive a) => Mod a where Source #
Represents a quotient group modulo some integer.
class (Additive a, Additive b) => Subgroup a b where Source #
Represents that a
is a subgroup of b
.
fromSubgroup :: a -> b Source #
class Reduce a b where Source #
Represents that b
is a quotient group of a
.
Instances
The type of representatives of b
.
Instances
type LiftOf (a, b) Source # | |
Defined in Crypto.Lol.Prelude | |
type LiftOf (ZqBasic q z) Source # | |
Defined in Crypto.Lol.Types.Unsafe.ZqBasic | |
type LiftOf (RRq q r) Source # | |
Defined in Crypto.Lol.Types.Unsafe.RRq | |
type LiftOf (Cyc t m r) Source # | |
Defined in Crypto.Lol.Cyclotomic.Cyc | |
type LiftOf (CycRep t D m r) Source # | |
type LiftOf (CycRep t P m r) Source # | |
type LiftOf (Linear c e r s zp) Source # | |
Defined in Crypto.Lol.Cyclotomic.Linear |
type Lift b a = (Lift' b, LiftOf b ~ a) Source #
Represents that b
can be lifted to a "short" a
congruent to b
.
class Reduce (LiftOf b) b => Lift' b where Source #
Fun-dep version of Lift.
Instances
(Mod a, Mod b, Lift' a, Lift' b, Reduce Integer (a, b), ToInteger (LiftOf a), ToInteger (LiftOf b)) => Lift' (a, b) Source # | Lift product ring of \(\Z_q\)s to |
Defined in Crypto.Lol.Prelude | |
(Reflects q z, Ring z, Ord z, IntegralDomain z) => Lift' (ZqBasic q z) Source # | |
(Reflects q r, Field r, Reduce r (RRq q r)) => Lift' (RRq q r) Source # | |
(Lift' r, IFunctor t, IFElt t r, IFElt t (LiftOf r), Fact m) => Lift' (CycRep t D m r) Source # | |
(Fact m, Lift' r, IFunctor t, IFElt t r, IFElt t (LiftOf r)) => Lift' (CycRep t P m r) Source # | |
class (Additive a, Additive b) => Rescale a b where Source #
Represents that a
can be rescaled to b
, as an "approximate"
additive homomorphism.
Instances
(Additive a, Rescale f (b, (c, (d, (e, f)))), Rescale (b, (c, (d, (e, f)))) (a, (b, (c, (d, (e, f)))))) => Rescale f (a, (b, (c, (d, (e, f))))) Source # | Rescale up by a product of five rings |
Defined in Crypto.Lol.Prelude | |
(Additive a, Rescale e (b, (c, (d, e))), Rescale (b, (c, (d, e))) (a, (b, (c, (d, e))))) => Rescale e (a, (b, (c, (d, e)))) Source # | Rescale up by a product of four rings |
Defined in Crypto.Lol.Prelude | |
(Additive a, Rescale d (b, (c, d)), Rescale (b, (c, d)) (a, (b, (c, d)))) => Rescale d (a, (b, (c, d))) Source # | Rescale up by a product of three rings |
Defined in Crypto.Lol.Prelude | |
(Additive a, Rescale c (b, c), Rescale (b, c) (a, (b, c))) => Rescale c (a, (b, c)) Source # | Rescale up by a product of two rings |
Defined in Crypto.Lol.Prelude | |
(Ring b, Mod a, Reduce (ModRep a) b) => Rescale b (a, b) Source # | Rescale up to a product ring of \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Ring a, Mod b, Reduce (ModRep b) a) => Rescale a (a, b) Source # | Rescale up to a product ring of \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Rescale ((a, b), c) (a, b), Rescale (a, b) a, Additive a, Additive c) => Rescale ((a, b), c) a Source # | Rescale a (multi-)product ring of \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Mod b, Field a, Lift b (ModRep b), Reduce (LiftOf b) a) => Rescale (a, b) a Source # | Rescale a product ring of \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Rescale (a, (b, (c, (d, (e, f))))) (b, (c, (d, (e, f)))), Rescale (b, (c, (d, (e, f)))) f, Additive a) => Rescale (a, (b, (c, (d, (e, f))))) f Source # | Rescale down by a product ring of five \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Rescale (a, (b, (c, (d, e)))) (b, (c, (d, e))), Rescale (b, (c, (d, e))) e, Additive a) => Rescale (a, (b, (c, (d, e)))) e Source # | Rescale down by a product ring of four \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Rescale (a, (b, (c, d))) (b, (c, d)), Rescale (b, (c, d)) d, Additive a) => Rescale (a, (b, (c, d))) d Source # | Rescale down by a product ring of three \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Rescale (a, (b, c)) (b, c), Rescale (b, c) c, Additive a, Additive c) => Rescale (a, (b, c)) c Source # | Rescale down by a product ring of two \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Mod a, Field b, Lift a (ModRep a), Reduce (LiftOf a) b) => Rescale (a, b) b Source # | Rescale a product ring of \(\Z_q\)s |
Defined in Crypto.Lol.Prelude | |
(Reflects q z, ToInteger z, Reflects q' z, Ring z) => Rescale (ZqBasic q z) (ZqBasic q' z) Source # | |
(Additive (RRq q r), Additive (RRq p r)) => Rescale (RRq q r) (RRq p r) Source # | |
(RescaleCyc (Cyc t m) a b, Fact m, Additive (Cyc t m a), Additive (Cyc t m b)) => Rescale (Cyc t m a) (Cyc t m b) Source # | Rescales relative to the powerful basis. This instance is
provided for convenience, but usage of |
(Rescale a b, TensorPowDec t a, TensorPowDec t b, Fact m) => Rescale (CycRep t D m a) (CycRep t D m b) Source # | |
(Rescale a b, TensorPowDec t a, TensorPowDec t b, Fact m) => Rescale (CycRep t P m a) (CycRep t P m b) Source # | |
class (Field src, Field tgt) => Encode src tgt where Source #
Represents that the target ring can "noisily encode" values from the source ring, in either "most significant digit" (MSD) or "least significant digit" (LSD) encodings, and provides conversion factors between the two types of encodings.
lsdToMSD :: (src, tgt) Source #
The factor that converts an element from LSD to MSD encoding in the target field, with associated scale factor to apply to correct the resulting encoded value.
Numeric
type Polynomial a = T a Source #
Sane synonym for T
.
type RealIntegral a = C a Source #
Sane synonym for C
.
type OrdFloat a = (Ord a, Transcendental a) Source #
Convenient synonym for (
Ord
a, Transcendental
a)
type RealTranscendental a = C a Source #
Sane synonym for C
.
type Transcendental a = C a Source #
Sane synonym for C
.
type ToRational a = C a Source #
Sane synonym for C
.
type IntegralDomain a = C a Source #
Sane synonym for C
.
type ZeroTestable a = C a Source #
Sane synonym for C
.
realToField :: (Field b, ToRational a) => a -> b Source #
The hidden NP function from Algebra.ToRational.
(^) :: forall a i. (Ring a, ToInteger i) => a -> i -> a Source #
Our custom exponentiation, overriding NP's version that
requires Integer
exponent.
Copied from http://hackage.haskell.org/package/base-4.7.0.0/docs/src/GHC-Real.html#%5E
modinv :: (PID i, Eq i) => i -> i -> Maybe i Source #
Inverse of \(a\) modulo \(q\), in range \([0,q-1]\). (Argument order is infix-friendly.)
decomp :: (IntegralDomain z, Ord z) => [z] -> z -> [z] Source #
Decompose an element into a list of "centered" digits with respect to relative radices.
roundMult :: (RealField r, ToInteger i) => i -> r -> i Source #
Deterministically round to the nearest multiple of \( i \).
roundScalarCentered :: (RealField r, Random r, ToInteger i, MonadRandom mon) => i -> r -> mon i Source #
Randomly round to the nearest larger or smaller multiple of \( i \), where the round-off term has expectation zero.
:: IntegralDomain i | |
=> i | dividend \(a\) |
-> i | divisor \(b\) |
-> (i, i) | (quotient, remainder) |
Variant of divMod
in which the remainder
is in the range \([-b/2,b/2)\).
(++) :: [a] -> [a] -> [a] infixr 5 #
Append two lists, i.e.,
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn] [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
If the first list is not finite, the result is the first list.
The value of seq a b
is bottom if a
is bottom, and
otherwise equal to b
. In other words, it evaluates the first
argument a
to weak head normal form (WHNF). seq
is usually
introduced to improve performance by avoiding unneeded laziness.
A note on evaluation order: the expression seq a b
does
not guarantee that a
will be evaluated before b
.
The only guarantee given by seq
is that the both a
and b
will be evaluated before seq
returns a value.
In particular, this means that b
may be evaluated before
a
. If you need to guarantee a specific order of evaluation,
you must use the function pseq
from the "parallel" package.
filter :: (a -> Bool) -> [a] -> [a] #
filter
, applied to a predicate and a list, returns the list of
those elements that satisfy the predicate; i.e.,
filter p xs = [ x | x <- xs, p x]
print :: Show a => a -> IO () #
The print
function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show
; print
converts values to strings for output using the show
operation and
adds a newline.
For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])
map :: (a -> b) -> [a] -> [b] #
map
f xs
is the list obtained by applying f
to each element
of xs
, i.e.,
map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] map f [x1, x2, ...] == [f x1, f x2, ...]
($) :: (a -> b) -> a -> b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs
Note that ($)
is levity-polymorphic in its result type, so that
foo $ True where foo :: Bool -> Int#
is well-typed
realToFrac :: (Real a, Fractional b) => a -> b #
general coercion to fractional types
The Bounded
class is used to name the upper and lower limits of a
type. Ord
is not a superclass of Bounded
since types that are not
totally ordered may also have upper and lower bounds.
The Bounded
class may be derived for any enumeration type;
minBound
is the first constructor listed in the data
declaration
and maxBound
is the last.
Bounded
may also be derived for single-constructor datatypes whose
constituent types are in Bounded
.
Instances
Class Enum
defines operations on sequentially ordered types.
The enumFrom
... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum
may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum
from 0
through n-1
.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded
as well as Enum
,
the following should hold:
- The calls
andsucc
maxBound
should result in a runtime error.pred
minBound
fromEnum
andtoEnum
should give a runtime error if the result value is not representable in the result type. For example,
is an error.toEnum
7 ::Bool
enumFrom
andenumFromThen
should be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound enumFromThen x y = enumFromThenTo x y bound where bound | fromEnum y >= fromEnum x = maxBound | otherwise = minBound
the successor of a value. For numeric types, succ
adds 1.
the predecessor of a value. For numeric types, pred
subtracts 1.
Convert from an Int
.
Convert to an Int
.
It is implementation-dependent what fromEnum
returns when
applied to a value that is too large to fit in an Int
.
Used in Haskell's translation of [n..]
with [n..] = enumFrom n
,
a possible implementation being enumFrom n = n : enumFrom (succ n)
.
For example:
enumFrom 4 :: [Integer] = [4,5,6,7,...]
enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound :: Int]
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
with [n,n'..] = enumFromThen n n'
, a possible implementation being
enumFromThen n n' = n : n' : worker (f x) (f x n')
,
worker s v = v : worker s (s v)
, x = fromEnum n' - fromEnum n
and
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y
For example:
enumFromThen 4 6 :: [Integer] = [4,6,8,10...]
enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound :: Int]
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m]
with
[n..m] = enumFromTo n m
, a possible implementation being
enumFromTo n m
| n <= m = n : enumFromTo (succ n) m
| otherwise = []
.
For example:
enumFromTo 6 10 :: [Int] = [6,7,8,9,10]
enumFromTo 42 1 :: [Integer] = []
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m]
with
[n,n'..m] = enumFromThenTo n n' m
, a possible implementation
being enumFromThenTo n n' m = worker (f x) (c x) n m
,
x = fromEnum n' - fromEnum n
, c x = bool (>=) ((x 0)
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y
and
worker s c v m
| c v m = v : worker s c (s v) m
| otherwise = []
For example:
enumFromThenTo 4 2 -6 :: [Integer] = [4,2,0,-2,-4,-6]
enumFromThenTo 6 8 2 :: [Int] = []
Instances
The Eq
class defines equality (==
) and inequality (/=
).
All the basic datatypes exported by the Prelude are instances of Eq
,
and Eq
may be derived for any datatype whose constituents are also
instances of Eq
.
The Haskell Report defines no laws for Eq
. However, ==
is customarily
expected to implement an equivalence relationship where two values comparing
equal are indistinguishable by "public" functions, with a "public" function
being one not allowing to see implementation details. For example, for a
type representing non-normalised natural numbers modulo 100, a "public"
function doesn't make the difference between 1 and 201. It is expected to
have the following properties: