Copyright | (c) 2011-2015 diagrams-lib team (see LICENSE) |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | diagrams-discuss@googlegroups.com |
Safe Haskell | None |
Language | Haskell2010 |
A module to re-export most of the functionality of the diagrams core and standard library.
- module Diagrams
- module Data.Default.Class
- module Data.Colour
- module Data.Colour.Names
- module Data.Colour.SRGB
- module Data.Semigroup
- module Linear.Vector
- module Linear.Affine
- module Linear.Metric
- module Data.Active
- module Control.Lens
- class Functor f => Applicative (f :: * -> *) where
- (*>) :: Applicative f => forall a b. f a -> f b -> f b
- (<*) :: Applicative f => forall a b. f a -> f b -> f a
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<$) :: Functor f => forall a b. a -> f b -> f a
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA2 :: Applicative f => forall a b c. (a -> b -> c) -> f a -> f b -> f c
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
Diagrams library
Exports from this library for working with diagrams.
module Diagrams
Convenience re-exports from other packages
module Data.Default.Class
For representing and operating on colors.
module Data.Colour
A large list of color names.
module Data.Colour.Names
Specify your own colours.
module Data.Colour.SRGB
Semigroups and monoids show up all over the place, so things from Data.Semigroup and Data.Monoid often come in handy.
module Data.Semigroup
For computing with vectors.
module Linear.Vector
For computing with points and vectors.
module Linear.Affine
For computing with dot products and norm.
module Linear.Metric
For working with Active
(i.e. animated) things.
module Data.Active
Most of the lens package. The following functions are not exported from lens because they either conflict with diagrams or may conflict with other libraries:
module Control.Lens
class Functor f => Applicative (f :: * -> *) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(
<*>
) = liftA2
id
liftA2
f x y = f <$>
x <*>
y
Further, any definition must satisfy the following:
- identity
pure
id
<*>
v = v- composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- homomorphism
pure
f<*>
pure
x =pure
(f x)- interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
(*>) :: Applicative f => forall a b. f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: Applicative f => forall a b. f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
liftA :: Applicative f => (a -> b) -> f a -> f b #
liftA2 :: Applicative f => forall a b c. (a -> b -> c) -> f a -> f b -> f c #
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.