| Safe Haskell | None |
|---|
Data.Reflection.Extras
- using :: forall p a. ReifiableConstraint p => Def p a -> (p a => a) -> a
- usingT :: forall p f a. ReifiableConstraint p => Def p a -> (p a => f a) -> f a
- reifyInstance :: Def p a -> (forall s. Reifies s (Def p a) => Proxy s -> r) -> r
- with :: forall p a. Def p a -> (forall s. Reifies s (Def p a) => Lift p s a) -> a
- data Lift p s a
- class ReifiableConstraint p where
- class Show a where
- class Read a where
- class Eq a => Ord a where
- class Eq a where
- class FromJSON a where
- class ToJSON 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 Bounded a where
- class Num a where
- class (Num a, Ord a) => Real a where
- toRational :: a -> Rational
- class Monoid a where
Documentation
using :: forall p a. ReifiableConstraint p => Def p a -> (p a => a) -> aSource
Choose a dictionary for a local type class instance.
>>>using (Monoid (+) 0) $ mempty <> 10 <> 12> 12
usingT :: forall p f a. ReifiableConstraint p => Def p a -> (p a => f a) -> f aSource
Instances
| Functor (Lift p s) | |
| Applicative (Lift p s) | |
| Reifies * s (Def Bounded a) => Bounded (Lift Bounded s a) | |
| Reifies * s (Def Enum a) => Enum (Lift Enum s a) | |
| Reifies * s (Def Eq a) => Eq (Lift Eq s a) | |
| Reifies * s (Def Ord a) => Eq (Lift Ord s a) | |
| Reifies * s (Def Real a) => Eq (Lift Real s a) | |
| Reifies * s (Def Num a) => Num (Lift Num s a) | |
| Reifies * s (Def Real a) => Num (Lift Real s a) | |
| Reifies * s (Def Ord a) => Ord (Lift Ord s a) | |
| Reifies * s (Def Real a) => Ord (Lift Real s a) | |
| Reifies * s (Def Read a) => Read (Lift Read s a) | |
| Reifies * s (Def Real a) => Real (Lift Real s a) | |
| Reifies * s (Def Show a) => Show (Lift Show s a) | |
| Reifies * s (Def ToJSON a) => ToJSON (Lift ToJSON s a) | |
| Reifies * s (Def FromJSON a) => FromJSON (Lift FromJSON s a) | |
| Reifies * s (Def Monoid a) => Monoid (Lift Monoid s a) |
class ReifiableConstraint p whereSource
class Show a where
Conversion of values to readable Strings.
Minimal complete definition: showsPrec or show.
Derived instances of Show have the following properties, which
are compatible with derived instances of Read:
- The result of
showis a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrecwill produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
xis less thand(associativity is ignored). Thus, ifdis0then the result is never surrounded in parentheses; ifdis11it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
showwill produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show is equivalent to
instance (Show a) => Show (Tree a) where
showsPrec d (Leaf m) = showParen (d > app_prec) $
showString "Leaf " . showsPrec (app_prec+1) m
where app_prec = 10
showsPrec d (u :^: v) = showParen (d > up_prec) $
showsPrec (up_prec+1) u .
showString " :^: " .
showsPrec (up_prec+1) v
where up_prec = 5
Note that right-associativity of :^: is ignored. For example,
-
produces the stringshow(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)".
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> a | the value to be converted to a |
| -> ShowS |
Convert a value to a readable String.
showsPrec should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that showsPrec started with.
Instances
class Read a where
Parsing of Strings, producing values.
Minimal complete definition: readsPrec (or, for GHC only, readPrec)
Derived instances of Read make the following assumptions, which
derived instances of Show obey:
- If the constructor is defined to be an infix operator, then the
derived
Readinstance will parse only infix applications of the constructor (not the prefix form). - Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived
Readwill parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Readinstance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Read in Haskell 98 is equivalent to
instance (Read a) => Read (Tree a) where
readsPrec d r = readParen (d > app_prec)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec (app_prec+1) s]) r
++ readParen (d > up_prec)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec (up_prec+1) r,
(":^:",t) <- lex s,
(v,w) <- readsPrec (up_prec+1) t]) r
where app_prec = 10
up_prec = 5
Note that right-associativity of :^: is unused.
The derived instance in GHC is equivalent to
instance (Read a) => Read (Tree a) where
readPrec = parens $ (prec app_prec $ do
Ident "Leaf" <- lexP
m <- step readPrec
return (Leaf m))
+++ (prec up_prec $ do
u <- step readPrec
Symbol ":^:" <- lexP
v <- step readPrec
return (u :^: v))
where app_prec = 10
up_prec = 5
readListPrec = readListPrecDefault
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> ReadS a |
attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that
showsPrec started with.
Instances
| Read Bool | |
| Read Char | |
| Read Double | |
| Read Float | |
| Read Int | |
| Read Integer | |
| Read Ordering | |
| Read Word | |
| Read () | |
| Read Text | |
| Read UTCTime | |
| Read DotNetTime | |
| Read All | |
| Read Any | |
| Read Arity | |
| Read Fixity | |
| Read Associativity | |
| Read Lexeme | |
| Read Text | |
| Read Void | Reading a |
| Read LensFlag | |
| Read LocalTime | |
| Read ZonedTime | |
| Read TimeOfDay | |
| Read TimeZone | |
| Read Day | |
| Read a => Read [a] | |
| (Integral a, Read a) => Read (Ratio a) | |
| Read a => Read (Maybe a) | |
| Read a => Read (Dual a) | |
| Read a => Read (Sum a) | |
| Read a => Read (Product a) | |
| Read a => Read (First a) | |
| Read a => Read (Last a) | |
| a => Read (Dict a) | |
| (Read a, Prim a) => Read (Vector a) | |
| (Read a, Storable a) => Read (Vector a) | |
| (Read a, Unbox a) => Read (Vector a) | |
| Read a => Read (Vector a) | |
| (Read a, Read b) => Read (a, b) | |
| (Ix a, Read a, Read b) => Read (Array a b) | |
| (SingRep k a rep, Read rep, Eq rep) => Read (Sing k a) | |
| Read (Proxy k s) | |
| (Read a, Read b, Read c) => Read (a, b, c) | |
| Reifies * s (Def Read a) => Read (Lift Read s a) | |
| (Read a, Read b, Read c, Read d) => Read (a, b, c, d) | |
| (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | |
| (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) |
The Ord class is used for totally ordered datatypes.
Instances of Ord can be derived for any user-defined
datatype whose constituent types are in Ord. The declared order
of the constructors in the data declaration determines the ordering
in derived Ord instances. The Ordering datatype allows a single
comparison to determine the precise ordering of two objects.
Minimal complete definition: either compare or <=.
Using compare can be more efficient for complex types.
Instances
| Ord Bool | |
| Ord Char | |
| Ord Double | |
| Ord Float | |
| Ord Int | |
| Ord Integer | |
| Ord Ordering | |
| Ord Word | |
| Ord Name | |
| Ord () | |
| Ord Text | |
| Ord DotNetTime | |
| Ord All | |
| Ord Any | |
| Ord Arity | |
| Ord Fixity | |
| Ord Associativity | |
| Ord Text | |
| Ord Void | |
| Ord LensFlag | |
| Ord ModName | |
| Ord PkgName | |
| Ord OccName | |
| Ord NameFlavour | |
| Ord NameSpace | |
| Ord LocalTime | |
| Ord a => Ord [a] | |
| Integral a => Ord (Ratio a) | |
| Ord a => Ord (Dual a) | |
| Ord a => Ord (Sum a) | |
| Ord a => Ord (Product a) | |
| Ord a => Ord (First a) | |
| Ord a => Ord (Last a) | |
| Ord (Dict a) | |
| (Prim a, Ord a) => Ord (Vector a) | |
| (Storable a, Ord a) => Ord (Vector a) | |
| (Unbox a, Ord a) => Ord (Vector a) | |
| Ord a => Ord (Vector a) | |
| (Ord a, Ord b) => Ord (a, b) | |
| Ord (:- a b) | |
| Ord (Proxy k s) | |
| Ord a => Ord (Stream Id a) | |
| (Ord a, Ord b, Ord c) => Ord (a, b, c) | |
| Reifies * s (Def Ord a) => Ord (Lift Ord s a) | |
| Reifies * s (Def Real a) => Ord (Lift Real s a) | |
| (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) |
class Eq a where
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.
Instances
| Eq Bool | |
| Eq Char | |
| Eq Double | |
| Eq Float | |
| Eq Int | |
| Eq Integer | |
| Eq Ordering | |
| Eq Word | |
| Eq Exp | |
| Eq Match | |
| Eq Clause | |
| Eq Pat | |
| Eq Type | |
| Eq Dec | |
| Eq Name | |
| Eq FunDep | |
| Eq Pred | |
| Eq TyVarBndr | |
| Eq () | |
| Eq Con | |
| Eq Text | |
| Eq DotNetTime | |
| Eq Value | |
| Eq All | |
| Eq Any | |
| Eq Arity | |
| Eq Fixity | |
| Eq Associativity | |
| Eq Text | |
| Eq Void | |
| Eq LensFlag | |
| Eq ModName | |
| Eq PkgName | |
| Eq OccName | |
| Eq NameFlavour | |
| Eq NameSpace | |
| Eq Fixity | |
| Eq FixityDirection | |
| Eq Lit | |
| Eq Body | |
| Eq Guard | |
| Eq Stmt | |
| Eq Range | |
| Eq FamFlavour | |
| Eq Foreign | |
| Eq Callconv | |
| Eq Safety | |
| Eq Pragma | |
| Eq Inline | |
| Eq RuleMatch | |
| Eq Phases | |
| Eq RuleBndr | |
| Eq Strict | |
| Eq TyLit | |
| Eq LocalTime | |
| Eq a => Eq [a] | |
| Eq a => Eq (Ratio a) | |
| Eq (Q a) | |
| Eq a => Eq (Result a) | |
| Eq a => Eq (Dual a) | |
| Eq a => Eq (Sum a) | |
| Eq a => Eq (Product a) | |
| Eq a => Eq (First a) | |
| Eq a => Eq (Last a) | |
| Eq (Dict a) | |
| (Prim a, Eq a) => Eq (Vector a) | |
| (Storable a, Eq a) => Eq (Vector a) | |
| (Unbox a, Eq a) => Eq (Vector a) | |
| Eq a => Eq (Vector a) | |
| (Eq a, Eq b) => Eq (a, b) | |
| Eq (:- a b) | |
| Eq (Proxy k s) | |
| Eq a => Eq (Stream Id a) | |
| (Eq a, Eq b, Eq c) => Eq (a, b, c) | |
| Reifies * s (Def Eq a) => Eq (Lift Eq s a) | |
| Reifies * s (Def Ord a) => Eq (Lift Ord s a) | |
| Reifies * s (Def Real a) => Eq (Lift Real s a) | |
| (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) |
class FromJSON a where
A type that can be converted from JSON, with the possibility of failure.
When writing an instance, use empty, mzero, or fail to make a
conversion fail, e.g. if an Object is missing a required key, or
the value is of the wrong type.
An example type and instance:
{-# LANGUAGE OverloadedStrings #-}
data Coord { x :: Double, y :: Double }
instance FromJSON Coord where
parseJSON (Object v) = Coord <$>
v .: "x" <*>
v .: "y"
-- A non-Object value is of the wrong type, so use mzero to fail.
parseJSON _ = mzero
Note the use of the OverloadedStrings language extension which enables
Text values to be written as string literals.
Instead of manually writing your FromJSON instance, there are three options
to do it automatically:
- Data.Aeson.TH provides template-haskell functions which will derive an instance at compile-time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
- Data.Aeson.Generic provides a generic
fromJSONfunction that parses to any type which is an instance ofData. - If your compiler has support for the
DeriveGenericandDefaultSignatureslanguage extensions,parseJSONwill have a default generic implementation.
To use this, simply add a deriving clause to your datatype and
declare a GenericFromJSON instance for your datatype without giving a definition
for parseJSON.
For example the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord { x :: Double, y :: Double } deriving Generic
instance FromJSON Coord
Note that, instead of using DefaultSignatures, it's also possible
to parameterize the generic decoding using genericParseJSON applied
to your encoding/decoding Options:
instance FromJSON Coord where
parseJSON = genericParseJSON defaultOptions
Instances
class ToJSON a where
A type that can be converted to JSON.
An example type and instance:
{-# LANGUAGE OverloadedStrings #-}
data Coord { x :: Double, y :: Double }
instance ToJSON Coord where
toJSON (Coord x y) = object ["x" .= x, "y" .= y]
Note the use of the OverloadedStrings language extension which enables
Text values to be written as string literals.
Instead of manually writing your ToJSON instance, there are three options
to do it automatically:
- Data.Aeson.TH provides template-haskell functions which will derive an instance at compile-time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
- Data.Aeson.Generic provides a generic
toJSONfunction that accepts any type which is an instance ofData. - If your compiler has support for the
DeriveGenericandDefaultSignatureslanguage extensions (GHC 7.2 and newer),toJSONwill have a default generic implementation.
To use the latter option, simply add a deriving clause to your
datatype and declare a GenericToJSON instance for your datatype without giving a
definition for toJSON.
For example the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord { x :: Double, y :: Double } deriving Generic
instance ToJSON Coord
Note that, instead of using DefaultSignatures, it's also possible
to parameterize the generic encoding using genericToJSON applied
to your encoding/decoding Options:
instance ToJSON Coord where
toJSON = genericToJSON defaultOptions
Instances
class Enum a where
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
andsuccmaxBoundshould result in a runtime error.predminBound -
fromEnumandtoEnumshould give a runtime error if the result value is not representable in the result type. For example,is an error.toEnum7 ::Bool -
enumFromandenumFromThenshould 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
Methods
succ :: a -> a
the successor of a value. For numeric types, succ adds 1.
pred :: a -> a
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.
enumFrom :: a -> [a]
Used in Haskell's translation of [n..].
enumFromThen :: a -> a -> [a]
Used in Haskell's translation of [n,n'..].
enumFromTo :: a -> a -> [a]
Used in Haskell's translation of [n..m].
enumFromThenTo :: a -> a -> a -> [a]
Used in Haskell's translation of [n,n'..m].
class Bounded a where
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 Num a where
Basic numeric class.
Minimal complete definition: all except negate or (-)
Methods
(+) :: a -> a -> a
(*) :: a -> a -> a
(-) :: a -> a -> a
negate :: a -> a
Unary negation.
abs :: a -> a
Absolute value.
signum :: 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).
fromInteger :: Integer -> 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
Instances
| Num Double | |
| Num Float | |
| Num Int | |
| Num Integer | |
| Num Word | |
| Num Exp | This permits the use of $(5) as an expression splice. |
| Num Type | This permits the use of $(5) as a type splice. |
| Integral a => Num (Ratio a) | |
| Num a => Num (Q a) | |
| Reifies * s (Def Num a) => Num (Lift Num s a) | |
| Reifies * s (Def Real a) => Num (Lift Real s a) |
class Monoid a where
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat =
foldrmappend mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Minimal complete definition: mempty and mappend.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Sum and Product.
Methods
mempty :: a
Identity of mappend
mappend :: a -> a -> a
An associative operation
mconcat :: [a] -> a
Fold a list using the monoid.
For most types, the default definition for mconcat will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
| Monoid Ordering | |
| Monoid () | |
| Monoid Text | |
| Monoid All | |
| Monoid Any | |
| Monoid Text | |
| Monoid [a] | |
| Monoid a => Monoid (Maybe a) | Lift a semigroup into |
| Monoid (Result a) | |
| Monoid (Parser a) | |
| Monoid a => Monoid (Dual a) | |
| Monoid (Endo a) | |
| Num a => Monoid (Sum a) | |
| Num a => Monoid (Product a) | |
| Monoid (First a) | |
| Monoid (Last a) | |
| a => Monoid (Dict a) | |
| Prim a => Monoid (Vector a) | |
| Storable a => Monoid (Vector a) | |
| Unbox a => Monoid (Vector a) | |
| Monoid (Vector a) | |
| Monoid a => Monoid (May a) | |
| Monoid b => Monoid (a -> b) | |
| (Monoid a, Monoid b) => Monoid (a, b) | |
| Monoid (Jacket i a) | This is an illegal |
| Monoid a => Monoid (Err e a) | |
| Monoid (Proxy k s) | |
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | |
| Reifies * s (Def Monoid a) => Monoid (Lift Monoid s a) | |
| (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | |
| (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) |