| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Functor.Compat
Documentation
module Data.Functor
class Functor (f :: Type -> Type) where #
A type f is a Functor if it provides a function fmap which, given any types a and b
lets you apply any function from (a -> b) to turn an f a into an f b, preserving the
structure of f. Furthermore f needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap and
the first law, so you need only check that the former condition holds.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b #
Using ApplicativeDo: '' can be understood as
the fmap f asdo expression
do a <- as pure (f a)
with an inferred Functor constraint.
Instances
| Functor [] | Since: base-2.1 |
| Functor Maybe | Since: base-2.1 |
| Functor IO | Since: base-2.1 |
| Functor Solo | |
| Functor Complex | Since: base-4.9.0.0 |
| Functor Min | Since: base-4.9.0.0 |
| Functor Max | Since: base-4.9.0.0 |
| Functor First | Since: base-4.9.0.0 |
| Functor Last | Since: base-4.9.0.0 |
| Functor Option | Since: base-4.9.0.0 |
| Functor Identity | Since: base-4.8.0.0 |
| Functor Handler | Since: base-4.6.0.0 |
| Functor STM | Since: base-4.3.0.0 |
| Functor First | Since: base-4.8.0.0 |
| Functor Last | Since: base-4.8.0.0 |
| Functor Dual | Since: base-4.8.0.0 |
| Functor Sum | Since: base-4.8.0.0 |
| Functor Product | Since: base-4.8.0.0 |
| Functor ReadPrec | Since: base-2.1 |
| Functor ReadP | Since: base-2.1 |
| Functor NonEmpty | Since: base-4.9.0.0 |
| Functor P | Since: base-4.8.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| Functor (Either a) | Since: base-3.0 |
| Functor ((,) a) | Since: base-2.1 |
| Functor (Arg a) | Since: base-4.9.0.0 |
| Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Functor ((,,) a b) | Since: base-4.14.0.0 |
| Functor (Const m :: Type -> Type) | Since: base-2.1 |
| Functor f => Functor (Ap f) | Since: base-4.12.0.0 |
| Functor f => Functor (Alt f) | Since: base-4.8.0.0 |
| Functor ((->) r :: Type -> Type) | Since: base-2.1 |
| Functor ((,,,) a b c) | Since: base-4.14.0.0 |
| (Functor f, Functor g) => Functor (Product f g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Sum f g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Compose f g) | Since: base-4.9.0.0 |
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$.
Using ApplicativeDo: 'as ' can be understood as the
$> bdo expression
do as pure b
with an inferred Functor constraint.
Examples
Replace the contents of a with a constant
Maybe IntString:
>>>Nothing $> "foo"Nothing>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an
with a constant Either Int IntString, resulting in an :Either
Int String
>>>Left 8675309 $> "foo"Left 8675309>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: base-4.7.0.0
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Using ApplicativeDo: '' can be understood as the
void asdo expression
do as pure ()
with an inferred Functor constraint.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an
with unit, resulting in an Either Int Int:Either Int ()
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2