Safe Haskell | None |
---|
- data Fay a
- data Char
- type String = [Char]
- data Integer
- data Double
- data Bool
- class Show a where
- class Read a
- data Maybe a
- class Typeable a where
- class Typeable a => Data a where
- gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> a -> c a
- gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
- toConstr :: a -> Constr
- dataTypeOf :: a -> DataType
- dataCast1 :: Typeable1 t => (forall d. Data d => c (t d)) -> Maybe (c a)
- dataCast2 :: Typeable2 t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a)
- gmapT :: (forall b. Data b => b -> b) -> a -> a
- gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
- gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
- gmapQ :: (forall d. Data d => d -> u) -> a -> [u]
- gmapQi :: Int -> (forall d. Data d => d -> u) -> a -> u
- gmapM :: Monad m => (forall d. Data d => d -> m d) -> a -> m a
- gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a
- gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a
- class Monad m
- class Eq a where
- read :: Read a => String -> a
- fromInteger :: Integer -> Double
- fromRational :: Ratio Integer -> Double
- (>>) :: Fay a -> Fay b -> Fay b
- (>>=) :: Fay a -> (a -> Fay b) -> Fay b
- (+) :: Num a => a -> a -> a
- (*) :: Num a => a -> a -> a
- (-) :: Num a => a -> a -> a
- (>) :: Ord a => a -> a -> Bool
- (<) :: Ord a => a -> a -> Bool
- (>=) :: Ord a => a -> a -> Bool
- (<=) :: Ord a => a -> a -> Bool
- (/) :: Fractional a => a -> a -> a
- (||) :: Bool -> Bool -> Bool
- (&&) :: Bool -> Bool -> Bool
- fail :: String -> Fay a
- return :: a -> Fay a
- ($) :: (t1 -> t) -> t1 -> t
- (++) :: [a] -> [a] -> [a]
- (.) :: (t1 -> t) -> (t2 -> t1) -> t2 -> t
- data Ordering
- any :: (t -> Bool) -> [t] -> Bool
- compare :: Ord a => a -> a -> Ordering
- concat :: [[a]] -> [a]
- const :: a -> b -> a
- elem :: Eq a => a -> [a] -> Bool
- enumFrom :: Num a => a -> [a]
- enumFromTo :: (Eq t, Num t) => t -> t -> [t]
- filter :: (a -> Bool) -> [a] -> [a]
- find :: (a -> Bool) -> [a] -> Maybe a
- flip :: (t1 -> t2 -> t) -> t2 -> t1 -> t
- foldl :: (t1 -> t -> t1) -> t1 -> [t] -> t1
- foldr :: (t -> t1 -> t1) -> t1 -> [t] -> t1
- forM_ :: Monad m => [t] -> (t -> m a) -> m ()
- fst :: (t, t1) -> t
- length :: Num a => [t] -> a
- mod :: Double -> Double -> Double
- insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
- intercalate :: [a] -> [[a]] -> [a]
- intersperse :: a -> [a] -> [a]
- lookup :: Eq a1 => a1 -> [(a1, a)] -> Maybe a
- map :: (a -> b) -> [a] -> [b]
- mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
- maybe :: t -> (t1 -> t) -> Maybe t1 -> t
- not :: Bool -> Bool
- nub :: Eq a => [a] -> [a]
- null :: [t] -> Bool
- prependToAll :: a -> [a] -> [a]
- snd :: (t, t1) -> t1
- sort :: Ord a => [a] -> [a]
- sortBy :: (t -> t -> Ordering) -> [t] -> [t]
- when :: Monad m => Bool -> m a -> m ()
- zip :: [a] -> [b] -> [(a, b)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- max :: Double -> Double -> Double
- min :: Double -> Double -> Double
Documentation
The JavaScript FFI interfacing monad.
data Char
The character type Char
is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) characters (see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char
.
To convert a Char
to or from the corresponding Int
value defined
by Unicode, use toEnum
and fromEnum
from the
Enum
class respectively (or equivalently ord
and chr
).
Bounded Char | |
Enum Char | |
Eq Char | |
Data Char | |
Ord Char | |
Read Char | |
Show Char | |
Ix Char | |
Typeable Char | |
Generic Char | |
ToJSON Char | |
FromJSON Char | |
Hashable Char | |
ErrorList Char | |
Unbox Char | |
Foreign Char | Characters are OK. |
Reader FilePath | Simple file reader. |
Writer FilePath | Simple file writer. |
Vector Vector Char | |
MVector MVector Char | |
Monad m => Stream ByteString m Char | |
Monad m => Stream ByteString m Char | |
IsString [Char] | |
ToJSON [Char] | |
FromJSON [Char] | |
ToJSON v => ToJSON (HashMap String v) | |
ToJSON v => ToJSON (Map String v) | |
FromJSON v => FromJSON (HashMap String v) | |
FromJSON v => FromJSON (Map String v) |
data Integer
Arbitrary-precision integers.
data Double
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Enum Double | |
Eq Double | |
Floating Double | |
Fractional Double | |
Data Double | |
Num Double | |
Ord Double | |
Read Double | |
Real Double | |
RealFloat Double | |
RealFrac Double | |
Show Double | |
Typeable Double | |
Generic Double | |
ToJSON Double | |
FromJSON Double | |
Default Double | |
Hashable Double | |
Unbox Double | |
Foreign Double | All numbers in JS are double. |
Vector Vector Double | |
MVector MVector Double |
data Bool
class Show a where
Conversion of values to readable String
s.
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
show
is 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
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will 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)"
.
class Read a
Parsing of String
s, 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
Read
instance 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
Read
will parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Read
instance 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
Read Bool | |
Read Char | |
Read Double | |
Read Float | |
Read Int | |
Read Int8 | |
Read Int16 | |
Read Int32 | |
Read Int64 | |
Read Integer | |
Read Ordering | |
Read Word | |
Read Word8 | |
Read Word16 | |
Read Word32 | |
Read Word64 | |
Read () | |
Read ByteString | |
Read Text | |
Read UTCTime | |
Read DotNetTime | |
Read ByteString | |
Read Version | |
Read ExitCode | |
Read BufferMode | |
Read Newline | |
Read NewlineMode | |
Read All | |
Read Any | |
Read GeneralCategory | |
Read Lexeme | |
Read Text | |
Read Permissions | |
Read Arity | |
Read Fixity | |
Read Associativity | |
Read Extension | |
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) | |
Read a => Read (Vector a) | |
(Read a, Unbox a) => Read (Vector a) | |
(Read a, Read b) => Read (Either a b) | |
(Read a, Read b) => Read (a, b) | |
(Ix a, Read a, Read b) => Read (Array a b) | |
(Read a, Read b, Read c) => Read (a, b, c) | |
(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) |
data Maybe a
The Maybe
type encapsulates an optional value. A value of type
either contains a value of type Maybe
aa
(represented as
),
or it is empty (represented as Just
aNothing
). Using Maybe
is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error
.
The Maybe
type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing
. A richer
error monad can be built using the Either
type.
Monad Maybe | |
Functor Maybe | |
Typeable1 Maybe | |
MonadPlus Maybe | |
Applicative Maybe | |
Alternative Maybe | |
Eq a => Eq (Maybe a) | |
Data a => Data (Maybe a) | |
Ord a => Ord (Maybe a) | |
Read a => Read (Maybe a) | |
Show a => Show (Maybe a) | |
Generic (Maybe a) | |
ToJSON a => ToJSON (Maybe a) | |
FromJSON a => FromJSON (Maybe a) | |
Monoid a => Monoid (Maybe a) | Lift a semigroup into |
Default (Maybe a) | |
Hashable a => Hashable (Maybe a) |
class Typeable a where
The class Typeable
allows a concrete representation of a type to
be calculated.
class Typeable a => Data a where
The Data
class comprehends a fundamental primitive gfoldl
for
folding over constructor applications, say terms. This primitive can
be instantiated in several ways to map over the immediate subterms
of a term; see the gmap
combinators later in this class. Indeed, a
generic programmer does not necessarily need to use the ingenious gfoldl
primitive but rather the intuitive gmap
combinators. The gfoldl
primitive is completed by means to query top-level constructors, to
turn constructor representations into proper terms, and to list all
possible datatype constructors. This completion allows us to serve
generic programming scenarios like read, show, equality, term generation.
The combinators gmapT
, gmapQ
, gmapM
, etc are all provided with
default definitions in terms of gfoldl
, leaving open the opportunity
to provide datatype-specific definitions.
(The inclusion of the gmap
combinators as members of class Data
allows the programmer or the compiler to derive specialised, and maybe
more efficient code per datatype. Note: gfoldl
is more higher-order
than the gmap
combinators. This is subject to ongoing benchmarking
experiments. It might turn out that the gmap
combinators will be
moved out of the class Data
.)
Conceptually, the definition of the gmap
combinators in terms of the
primitive gfoldl
requires the identification of the gfoldl
function
arguments. Technically, we also need to identify the type constructor
c
for the construction of the result type from the folded term type.
In the definition of gmapQ
x combinators, we use phantom type
constructors for the c
in the type of gfoldl
because the result type
of a query does not involve the (polymorphic) type of the term argument.
In the definition of gmapQl
we simply use the plain constant type
constructor because gfoldl
is left-associative anyway and so it is
readily suited to fold a left-associative binary operation over the
immediate subterms. In the definition of gmapQr, extra effort is
needed. We use a higher-order accumulation trick to mediate between
left-associative constructor application vs. right-associative binary
operation (e.g., (:)
). When the query is meant to compute a value
of type r
, then the result type withing generic folding is r -> r
.
So the result of folding is a function to which we finally pass the
right unit.
With the -XDeriveDataTypeable
option, GHC can generate instances of the
Data
class automatically. For example, given the declaration
data T a b = C1 a b | C2 deriving (Typeable, Data)
GHC will generate an instance that is equivalent to
instance (Data a, Data b) => Data (T a b) where gfoldl k z (C1 a b) = z C1 `k` a `k` b gfoldl k z C2 = z C2 gunfold k z c = case constrIndex c of 1 -> k (k (z C1)) 2 -> z C2 toConstr (C1 _ _) = con_C1 toConstr C2 = con_C2 dataTypeOf _ = ty_T con_C1 = mkConstr ty_T "C1" [] Prefix con_C2 = mkConstr ty_T "C2" [] Prefix ty_T = mkDataType "Module.T" [con_C1, con_C2]
This is suitable for datatypes that are exported transparently.
:: (forall d b. Data d => c (d -> b) -> d -> c b) | defines how nonempty constructor applications are folded. It takes the folded tail of the constructor application and its head, i.e., an immediate subterm, and combines them in some way. |
-> (forall g. g -> c g) | defines how the empty constructor application is folded, like the neutral / start element for list folding. |
-> a | structure to be folded. |
-> c a | result, with a type defined in terms of |
Left-associative fold operation for constructor applications.
The type of gfoldl
is a headache, but operationally it is a simple
generalisation of a list fold.
The default definition for gfoldl
is
, which is
suitable for abstract datatypes with no substructures.
const
id
gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
Unfolding constructor applications
Obtaining the constructor from a given datum. For proper terms, this is meant to be the top-level constructor. Primitive datatypes are here viewed as potentially infinite sets of values (i.e., constructors).
dataTypeOf :: a -> DataType
The outer type constructor of the type
dataCast1 :: Typeable1 t => (forall d. Data d => c (t d)) -> Maybe (c a)
Mediate types and unary type constructors.
In Data
instances of the form T a
, dataCast1
should be defined
as gcast1
.
The default definition is
, which is appropriate
for non-unary type constructors.
const
Nothing
dataCast2 :: Typeable2 t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a)
Mediate types and binary type constructors.
In Data
instances of the form T a b
, dataCast2
should be
defined as gcast2
.
The default definition is
, which is appropriate
for non-binary type constructors.
const
Nothing
gmapT :: (forall b. Data b => b -> b) -> a -> a
A generic transformation that maps over the immediate subterms
The default definition instantiates the type constructor c
in the
type of gfoldl
to an identity datatype constructor, using the
isomorphism pair as injection and projection.
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
A generic query with a left-associative binary operator
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
A generic query with a right-associative binary operator
gmapQ :: (forall d. Data d => d -> u) -> a -> [u]
A generic query that processes the immediate subterms and returns a list of results. The list is given in the same order as originally specified in the declaratoin of the data constructors.
gmapQi :: Int -> (forall d. Data d => d -> u) -> a -> u
A generic query that processes one child by index (zero-based)
gmapM :: Monad m => (forall d. Data d => d -> m d) -> a -> m a
A generic monadic transformation that maps over the immediate subterms
The default definition instantiates the type constructor c
in
the type of gfoldl
to the monad datatype constructor, defining
injection and projection using return
and >>=
.
gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a
Transformation of at least one immediate subterm does not fail
gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a
Transformation of one immediate subterm with success
class Monad m
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Minimal complete definition: >>=
and return
.
Instances of Monad
should satisfy the following laws:
return a >>= k == k a m >>= return == m m >>= (\x -> k x >>= h) == (m >>= k) >>= h
Instances of both Monad
and Functor
should additionally satisfy the law:
fmap f xs == xs >>= return . f
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
Monad [] | |
Monad IO | |
Monad Maybe | |
Monad Result | |
Monad Parser | |
Monad ReadP | |
Monad P | |
Monad ParseResult | |
Monad Identity | |
Monad Vector | |
Monad Id | |
Monad Box | |
Monad P | |
Monad Fay | |
Monad Compile | |
Monad ((->) r) | |
Monad (Either e) | |
Monad (Parser t) | |
ArrowApply a => Monad (ArrowMonad a) | |
Monad m => Monad (MaybeT m) | |
Monad (Lex r) | |
Monad m => Monad (ListT m) | |
Monad m => Monad (IdentityT m) | |
Monad (DocM s) | |
Monad m => Monad (ReaderT r m) | |
Monad (ContT r m) | |
(Monad m, Error e) => Monad (ErrorT e m) | |
Monad m => Monad (StateT s m) | |
Monad m => Monad (StateT s m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
Monad (ParsecT s u m) | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
(Monoid w, Monad m) => Monad (RWST r w s m) |
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
.
The read
function reads input from a string, which must be
completely consumed by the input process.
fromInteger :: Integer -> DoubleSource
Just to satisfy GHC.
fromRational :: Ratio Integer -> DoubleSource
Just to satisfy GHC.
(/) :: Fractional a => a -> a -> a
fractional division
enumFromTo :: (Eq t, Num t) => t -> t -> [t]Source
intercalate :: [a] -> [[a]] -> [a]Source
intersperse :: a -> [a] -> [a]Source
prependToAll :: a -> [a] -> [a]Source