Title: Theory / Unimportant / CS / Programming / Haskell / typeclassopedia
Tags: computer_to_instruction seen_description typeToSuperType
On every note of this deck, unless a note says otherwise:
Language: Haskell
Language: Haskell

Function: fmap: (a->b) -> f a -> f b
Page: https://wiki.haskell.org/Typeclassopedia
Name: Covariant Functor
Function2: <$ = fmap . const
Axiom: fmap id = id
Subtype of: Functor
Axiom2: fmap (g . h) = (fmap g) . (fmap h)
Intuition: Computational context
Example: list, maybe

Instruction: x <$  g
Page: https://wiki.haskell.org/Typeclassopedia
Returns: Similar to g, where each element has been replaced by x. (fmap (const x) g)
Variables: f a functor
g :: f a
x :: b

Page: https://wiki.haskell.org/Typeclassopedia
Variables: fmap: (a -> b) -> (f a) -> f b
Smaller1: fmap id = id
Greater1: fmap (g . h) = (fmap g) . (fmap h)

Instruction: a $ b
Page: https://wiki.haskell.org/Typeclassopedia
Returns: a (b)
Intuition: Very low fixity, thus it can replace a parenthesis extending up to the right of the line

Instruction: $>
Page: https://wiki.haskell.org/Typeclassopedia
Returns: flip (<$)

Instruction: void
Page: https://wiki.haskell.org/Typeclassopedia
Returns: (() <$) i.e. ignore the argument
Typ: Functor f => f a -> f()

Typ: Applicative
Function: pure :: a -> f a (embeds a values as a functor element)
Page: https://wiki.haskell.org/Typeclassopedia
Function2: <*> f (a-> b) -> f a -> f b (applies a normal function to a functor element, returning a functor element)
Axiom: pure id <*> v = v
Function3: (*>) :: f a -> f b -> f b
a1 *> a2 = (id <$ a1) <*> a2
Subtype of: Functor
Axiom2: pure f <> pure x = pure (f x)
Function4: (<*) :: f a -> f b -> f a
  (<*) = liftA2 const
Axiom3: u <*> pure y = pure ($ y) <*> u
Function5: fmap g x = pure g <*>
Axiom4: u <*> (v <*> w) = pure (.) <*> u <*> v <*> w

Question: (Either e) as a functor
Answer: fmap _ (Left e) = Left e
fmap g (Right a) = Right (g a)

Question: ((,) e) as a functor
Answer: fmap g (e, a) = (e, g a)

Question: ((,) e) as an instance of applicative and monoid
Answer: pure a = (mempty,a)
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Answer2: (e', g) <*> (e, a) = (e'<>e, g a)
Answer3: mempty = (mempty, mempty) (assuming it's applied to a monoid)
Answer4: (e, a) <> (e', a') = (e<>e', a<> a') (assuming it's applied to a monoid)
Assuming: e is a Monoid

Question: Monoidal as an applicative
Answer: unit = pure ()
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Answer2: a ** b = (pure (\a -> pure (\b -> (a,b)))) <*> a <*> b

Instruction: liftA2
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Returns: same as <*> but for functions with two arguments
Typ: Applicative f => (a -> b -> c) -> f a -> f b -> f c

Instruction: <**>
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Returns: computes first argument, then second, and apply second to first.
Typ: Applicative f => f a -> f (a -> b) -> f b
Intuition: almost (flip <*>) but inverse order of computation

Instruction: unless
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Returns: when . not
Typ: Applicative f => Bool -> f () -> f ()

Typ: Monoidal f
Function: unit :: f()
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Function2: (**) :: f a -> f b -> f (a,b)
Axiom: unit ** v = v and u ** unit = u
Function3: g *** h = \ (x,y) -> (gx, hy)
Subtype of: Functor f
Axiom2: u ** (v ** w) = (u ** v) ** w
Axiom3: fmap (g *** h) (u ** v) = fmap g u ** fmap h v (this is a free theorem)

Definition: pure f <*> u_1 <*> ... <*> u_n
Page: https://wiki.haskell.org/Typeclassopedia#Functor
Context: Haskell
Notation: [$]\llbracket f u_1 \dots u_n\rrbracket[/$]

Name: The Reader monad and monoid of e
Definition: fmap = flip (.)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Variables: e a type
Notation: ((->) e)
Definition2: pure = const
Definition3: bind (g:: e-> a) (f :: a -> e -> b) :: e -> b
bind g f e= f (g e) e
Intuition: A monad in which some fixed parameter can be used to access some actual values. Elements of the monads are functions using this parameters
Definition4: mempty = const mempty (assuming it's applied to a monoid)
Definition5: g <> h = g e<> h e (assuming the type is applied to a monoid)

Name: The Writer monad of w
Definition: return a = (a, unit)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Variables: e a type
Notation: a-> (a,w)
Definition2: (a, w) >>= f =
let (a', w') = f a in
(a', w+w')
Conjdef: Type (a, w)
Intuition: e is a log, each action may add things to it
Assuming: w is a monoid

Name: The identity monad
Definition: return = W
Page: http://blog.sigfpe.com/2007/04/trivial-monad.html
Definition2: bind :: (a -> W b) -> (W a -> W b)
bind f (W x) = f x
Conjdef: Type
data W a = W a deriving Show

Name: The list monad, monoid and alternative
Definition: fmap = map
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Definition2: bind = concat . flip map
Conjdef: Type
[]
Definition3: return = (:: [])
Definition4: (<*>) :: [a -> b] -> [a] -> [b]
  gs <*> xs = [ g x | g <- gs, x <- xs ]
Definition5: empty = mempty = []
Definition6: mappend = (++)
Definition7: (<|>)= (++)

Name: The Maybe monad, monoid and alternative
Definition: return = Just
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Definition2: (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b
(Just x) >>= g = g x
Nothing  >>= _ = Nothing
Conjdef: Type
Maybe
Definition3: fail = const Nothing
Extra: fmap _ Nothing = Nothing
fmap g (Just x) = Just (g x)
Just f <*> Just a = Just (f a)
_ <*> _ = Nothing
Definition4: empty = mempty = Nothing
Definition5: Just a <> Just b = Just (a<>b)
_ <> _ = Nothing
Assuming the type is a monoid
Definition6: Just a <|>  = const $ Just a
Nothing <|> = id

Name: The State s monad
Definition: return a s = (a, s)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Definition2: (g:: s-> a -> b) <$> (h:: s -> a):: s-> b
g <$> h =
  \s -> g s (h s)
Conjdef: Type
s -> (a, s)
Definition3: (g :: s -> ((a -> b), s)) <*> (h :: s -> (a, s)) :: (s -> (b, s))
g <*> h =
  \s -> let a, s' = h s in
    let aToB, s'' = g s' in
      (aToB a, s'')
Intuition: Allow to have a state, evolving during the computation
Definition4: (g:: s-> (a,s)) >>= (h:: a -> s -> (b,s)) :: (s-> (b, s))
g>>= h =
  \s -> let (a,s') = g s in
    h a s'

Name: The Const s monad
Definition: return s = unit
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Definition2: g <$> h = unit
Conjdef: Type
Const a b = a
Definition3: g <*> h = unit
Intuition: Monad with a single value
Definition4: g >>= h = unit
Assuming: a has a value called unit

Name: The free monad from f TODO
Definition: return Var
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Variables: f a functor
Context: Haskell
Definition2: g <$> Var a = Var (g a)
g <$> Node v = Node (f.fmap g v)
Conjdef: Type
data Free f a = Var a
    | Node (f (Free f a))
Definition3: Var g <*> Var a = Var (g a)
Var g <*> Node v = ...
Definition4: g >>= h = ?

Name: Join
Definition: join = (>>= id)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: \(\mu\)
Example: Just 5
Example2: Nothing
Intuition: Transform a monad of monad into a simple monad
Typ: m (m a) -> m a
Applied to: join (Just (Just 5))
Applied to2: join (Just (Nothing:: Maybe Int))

Name: fmap f
Definition: bind . return
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: <$>
Example: [4, 8]
Example2: Nothing
Intuition: Apply a normal function in a functor
Typ: \((a->b)-> f a -> f b\)
Applied to: fmap (+1) [3, 7]
Applied to2: fmap (+1) Nothing

Name: return
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: \(\eta\)
Intuition: Insert a value inside the monad
Typ: a -> m a

Name: bind
Definition: join . flip fmap
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: >>=
Intuition: Perform the first action, passes its as argument to the second one
Typ: Monad m => m a -> (a-> m b) -> m b

Name: ap
Definition: liftM2 ($)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: <*>
Intuition: applies a normal function to a functor element, returning a functor element
Typ: Monad m => m (a-> b) -> m a -> m b

Name: liftM2
Definition: \a b -> do { a' <- a; b' <- b; return (f a' b') }
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Typ: (Monad m) => (a -> b -> c) -> (m a -> m b -> m c)

Name: sequence
Definition: foldr mcons (return [])
  where
    mcons p q = p >>= \x -> q >>= \y -> return (x : y)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Intuition: Execute each instruction of the input traversable, return the list of result as a monad
Typ: Monad m, Traversable t => t (m a) -> m (t a)

Name: sequence_
Definition: foldr (>>) (return ())
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Typ: Monad m, Traversable t => t (m a) -> m ()

Name: replicateM
Definition: \i -> sequence . replicate i . return
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Typ: Monad m => Int -> m a -> m [a]

Name: forM
Definition: flip mapM
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Typ: Monad m, Traversable t => t a -> (a -> m b) -> m (t b)

Name: mapM
Definition: sequence. map
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Typ: Monad m, Traversable t => (a -> m b) ->  t a -> m (t b)

Definition: flip (>=>)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: <=<

Name: fish
Definition: \f, g -> (>>= g) . f
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Notation: >=>
Typ: Monad m => (a -> m b) -> (b -> m c) -> a -> m c

Typ: Monoid a
Function: mempty :: a
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Function2: mappend <> :: a -> a -> a
Context: Haskell
Axiom: mempty is an identity for mappend
Function3: mconcat :: [a] -> a
mconcat = foldr mappend mempty
Axiom2: mappend is associative

Name: mappend
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell monoid
Notation: <>
Typ: a -> a -> a

Typ: Sum
Meaning: An integer, as an element of the monoid under addition
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: Product
Meaning: An integer, as an element of the monoid under product
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: Any
Meaning: A Bool, as an element of the monoid under disjunction
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: All
Meaning: A Bool, as an element of the monoid under conjunction
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: First
Meaning: A Maybe type, as an instance of monoid, selecting the first Just item
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: Last
Meaning: A Maybe type, as an instance of monoid, selecting the last Just item
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Typ: Endo a
Meaning: Monoid of functions a->a under composition
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Language: Haskell

Name: The ordering monoid
Definition: mempty = EQ
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Definition2: EQ `mappend` = id
x `mappend` =const x
Intuition: Lexicographical order
Typ: LT | EQ | GT

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: (:) <$> v <*> many v
where many v = some v <|> pure []
Context: Alternative
Instruction: some v
Intuition: At least one instance of v, maybe more

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: some v <|> pure []
  where some v = (:) <$> v <*> many v
Context: Alternative
Instruction: many v
Intuition: Any number (potentially 0) value for v

Typ: Alternative f
Function: empty :: f a
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Function2: (<|>) :: f a -> f a -> f a
Context: Haskell Alternative
Axiom: (empty, <|>) is a monoid
Function3: some :: f a -> f [a]
some v = (:) <$> v <*> many v
Subtype of: Applicative f
Axiom2: empty <*> f = empty (some want the same on right)
Function4: many :: f a -> f [a]
many v = some v <|> pure []

Typ: MonadPlus m
Function: mzero :: m a
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Function2: mplus :: m a -> m a -> m a
Context: Haskell Alternative
Axiom: (mzero, mplus) is a monoid
Subtype of: Monad m

Typ: ArrowZero arr
Function: zeroArrow :: b `arr` c
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell Alternative
Subtype of: Arrow arr

Typ: ArrowPlus arr
Function: (<+>) :: (b `arr` c) -> (b `arr` c) -> (b `arr` c)
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell Alternative
Subtype of: ArrowZero arr

Question: IO as an Alternative
Answer: empty is I/O Exception
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Answer2: I/O Exception <|> = id
x <|> = const x

Question: async as an Alternative
Answer: empty is an action which runs forever
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Answer2: x <|> y = the action between x and y which ends first

Question: parser as an Alternative
Answer: empty is a parse failure
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell
Answer2: p1<|>p2 tries parsing p1, if it succeeds then p1 else try p2

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: \p -> if p then pure() else empty
Instruction: guard
Typ: Alternative f => Bool -> f ()
Intuition: create a conditional failure point in the middle of a computation, where the computation only proceeds if a certain condition holds.

Typ: Foldable t
Function: either
foldr :: (a -> b -> b) -> b -> t a -> b
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Function2: or
foldMap :: Monoid m => (a -> m) -> t a -> m
Context: Haskell

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: foldMap id
Context: Foldable
Instruction: fold

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: foldr (\a, b -> b<> (f a))
Context: Foldable
Instruction: foldMap f

Page: https://wiki.haskell.org/Typeclassopedia#Monad
Implementation: foldMap $ Endo . f
Context: Foldable
Instruction: foldr f

Question: Type of foldmap . foldmap
Answer: Monoid m, Foldable t1, Foldable t2 => (a -> m) -> t1 t2 a -> m
Page: https://wiki.haskell.org/Typeclassopedia#Monad
Context: Haskell Foldable
Extra: \x -> folmap (foldmap x)

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: getSum . foldMap (const (Sum 1))
Context: Traversable
Instruction: length

Instruction: getSum
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: traversable
Returns: identity
Typ: Sum a-> a

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: foldMap (\a -> if p a then [a] else [])
Returns: List of elements of foldable satisfying the predicate
Context: Traversable
Instruction: filterF
Typ: Foldable f => (a->Bool) -> f a -> [a]

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: foldMap (: [])
Context: Traversable
Instruction: toList
Typ: Foldable f => f a -> [a]

Instruction: getAny
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: traversable
Returns: Identity
Typ: Any -> Bool

Instruction: getAll
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: traversable
Returns: Identity
Typ: All -> Bool

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: Monoid.getAll . Foldable.foldMap (const (Monoid.All False))
Context: Traversable
Instruction: null

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \value -> Monoid.getAny . Foldable.foldMap (\x -> Monoid.Any(if value == x then True else False))
Returns: Whether the first argument occur in the second one
Context: Traversable
Instruction: elem
Typ: Foldable t, Eq a => a t a -> Bool

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \value -> Monoid.getAny . Foldable.foldMap (\x -> Monoid.Any(if value == x then True else False))
Returns: takes a container full of computations and combines them using (<|>).
Instruction: asum
Typ: (Alternative f, Foldable t) => t (f a) -> f a

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: traverse_ =<<
Returns: takes a container full of computations and runs them in sequence, discarding the results
Instruction: sequenceA_
Typ: (Applicative f, Foldable t) => t (f a) -> f ()

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: (sequenceA_ .) . (=<<)
Returns: applies the given function to each element in a foldable container and sequences the effects (but discards the results).
Instruction: traverse_
Typ: (Applicative f, Foldable t) => (a -> f b) -> t a -> f ()

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: flip traverse_
Returns: applies the given function to each element in a foldable container and sequences the effects (but discards the results).
Instruction: for_
Typ: Applicative f, Foldable t) => t a -> (a -> f b) -> f ()

Typ: Traversable t
Function: either
traverse  :: Applicative f => (a -> f b) -> t a -> f (t b)
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Function2: or
sequenceA :: Applicative f => t (f a) -> f (t a)
Context: Haskell
Axiom: traverse Identity = Identity
where Identity is the Identity functor
Subtype of: Functor t, Foldable t
Axiom2: traverse (Compose . fmap g . f) = Compose . fmap (traverse g) . traverse f
where Compose is the composition of functors

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \f -> sequenceA . fmap f
Returns: Apply a function creating applicative instance, transforming the whole Traversable in an applicative instance
Context: Traversable t
Instruction: traverse
Typ: Applicative f => (a -> f b) -> t a -> f (t b)

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: traverse id
Returns: Transform a traversable of Applicative into an applicative of traversable
Context: Traversable t
Instruction: sequenceA
Typ: Applicative f => t (f a) -> f (t a)

Question: traverse . traverse's type is
Answer: (a -> f b) -> t' (t a) -> f (t' (t b))
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Haskell Traversable t
Extra: traverse . traverse's = \x -> traverse (traverse x)
x ->
traverse(2) :: (a -> f b) -> t a -> f (t b)
traverse(1) :: (a' -> f' b') -> t' a' -> f' (t' b')
x = (a -> f b)
traverse x :: t a -> f (t b)
(a' -> f' b') = t a -> f (t b)
a' = t a
f' = f
b' = t b
traverse (traverse x) :: t' t a -> f (t' t b)
\x -> traverse (traverse x) :: (a -> f b) -> t' t a -> f (t' t b)

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: fmap f = runIdentity . traverse (Identity . f)
Returns: fmap, using Traversable function
Context: Traversable
Instruction: fmapDefault

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: getConst . traverse (Const . f)
Returns: foldMap using Traversable values
Context: Traversable
Instruction: foldMapDefault

Typ: Bifunctor
Function: either
bimap  :: (a -> b) -> (c -> d) -> p a c -> p b d
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Function2: or
first  :: (a -> b) -> p a c -> p b c
  second :: (b -> c) -> p a b -> p a c
Context: Haskell
Axiom: bimap f g = first f . second g
Axiom2: second = bimap id
first = flip bimap $ id
Example: (,),
Either
Const
Axiom3: bimap id id = id
first id    = id
second   id = id

Name: Pair as bifunctor
Definition: bimap f g (a, b) = (f a, g b)
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Haskell
Notation: (,)

Name: Either as bifunctor
Definition: bimap f g (Left a) = Left (f a)
bimap f g (Right b) = Right (g b)
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Haskell

Name: Const as bifunctor
Definition: bimap f g (Const a) = Const (f a)
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Haskell

Function: id  :: cat a a
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Name: Const as bifunctor
Function2: (.) :: cat b c -> cat a b -> cat a c
Context: Haskell
Example: ->
Kleisli
Extra: Category arr

Instruction: >>>
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: (.) in Category typeclass

Instruction: <<<«
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: flip (.) in Category typeclass

Typ: Arrow cat
Function: arr :: (b -> c) -> (cat b c)
Transform a function in an arrow
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Function2: first :: (cat b c) -> (cat (b, d) (c, d))
Apply an arrow to first element of a tuple
equal to (*** id)
Context: Haskell
Axiom: arr id = id arr (h . g) = arr g >>> arr h first (arr g) = arr (g *** id) first (g >>> h) = first g >>> first h first g >>> arr (id *** h) = arr (id *** h) >>> first g first g >>> arr fst = arr fst >>> g first (first g) >>> arr assoc = arr assoc >>> first g assoc ((x,y),z) = (x,(y,z))
Function3: second :: (cat b c) -> (cat (d, b) (d, c))
\arr -> swap . first arr . swap
Subtype of: Category cat
Example: ->, Kleisli m
Function4: (***) :: (cat b c) -> (cat b' c') -> (cat (b, b') (c, c'))
Parallel composition of arrows
\l r -> first l >>> second r
Function5: (&&&) :: (cat b c) -> (cat b c') -> (cat b (c, c'))
"fanout composition"
Apply two functions to same input

Instruction: arr
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Arrow cat
Returns: Similar to pure and return. Transform a method into an arrow
Typ: b -> c -> (cat b c)

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: (*** id)
Returns: Apply an arrow to first element of a tuple
Context: Arrow cat
Instruction: first
Typ: (cat b c) -> (cat (b, d) (c,d))

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \arr -> swap . first arr . swap
Returns: Apply an arrow to second element of a pair
Context: Arrow cat
Instruction: second
Typ: (cat b c) -> (cat (d, b) (d, c))

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \l r -> first l >>> second r
Name: parallel composition
Returns: Gien two arrows, apply both arrows on two side of a pair
Context: Arrow cat
Instruction: (***)

Instruction: &&&
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Arrow cat
Returns: Given two arrows with same input type, create an arrow returning both values
Name: fanout composition

Typ: ArrowChoice cat
Function: (+++):: (cat b c) -> (cat b' c') -> (cat (Either b b') (Either c c'))
l +++ r = (left l)>>> (right r)
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Function2: left :: (cat b c) -> Cat (Either b d) (Either c d)
left = (id +++)
right :: (cat b c) -> Cat (Either d b) (Either d c)
right = (+++ id)
Context: Haskell
Arrow cat
Function3: (|||) :: (cat b d) -> (cat c d) -> cat (Either b c) d
merge/fanin
Subtype of: Arrow cat

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: (id +++)
Returns: Apply an arrow if the value is on left side of an arrow
Context: ArrowChoice cat
Instruction: left

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Implementation: \l r -> (left l)>>> (right r)
Name: multiplexing
Returns: Apply a distinct function depending on whether an either value is left or right
Context: ArrowChoice cat
Instruction: +++

Instruction: |||
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: ArrowChoice cat
Returns: Apply one of two methods depending on whether it's a left or right part of a Either, and then ignore the side which was chosen before
Name: merge/fanin

Typ: ArrowApply cat
Function: app ::  cat (cat b c, b) c
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Context: Haskell
ArrowChoice cat
Subtype of: Arrow cat

Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Smaller to greater: is expressively equivalent to
Smaller1: ArrowApply
Greater1: Monad
Context: Haskell

Typ: Comonad w
Function: extract :: w a -> a
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Function2: duplicate :: w a -> w (w a)
duplicate = extend id
Function3: extend :: (w a -> b) -> w a -> w b
extend f = fmap f . duplicate
Subtype of: Functor w
Example: Stream

Name: The Stream comonad
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Definition2: duplicate :: Stream a -> Stream (Stream a)
duplicate s@(Cons x xs) = Cons s (duplicate xs)
Example: extract :: Stream a -> a
extract (Cons x _) = x
Definition3: extend :: (Stream a -> b) -> Stream a -> Stream b
extend g s@(Cons x xs)  = Cons (g s) (extend g xs)
Typ: data Stream a = Cons a (Stream a)

Typ: MonadFail m
Function: fail :: String -> m a
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Axiom: fail s >>= m = fail s
Subtype of: Monad m

Instruction: IdentityT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which lead to identity

Instruction: StateT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds a read-write state

Instruction: ReaderT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds a read-only environment

Instruction: WriterT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds a write-only log

Instruction: RWST
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which combines ReaderT, WriterT and StateT

Instruction: MaybeT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds the possibility of a failure

Instruction: ErrorT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds an arbitrary type to represent errors

Instruction: ListT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds non determinism

Instruction: ContT
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Returns: Monad transformer which adds continuation handling

Typ: MonadTrans t
Function: lift :: Monad m => m a -> t m a
Page: https://wiki.haskell.org/Typeclassopedia#Monoid
Axiom: lift . return   =  return
Axiom2: lift (m >>= f)  =  lift m >>= (lift . f)
Assuming: t: (* -> * -> *)

Typ: Fix
Page: http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html
Language: Haskell
Implementation: data F? f = F? (f (F? f))
Etymology: the fixed point of a functor

Typ: Free f r
Page: http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html
Language: Haskell
Implementation: data F? f r =
  | F? (f (F? f r))
  | Pure r
Name: Free monad

Typ: Contravariant f
Function: contramap :: (b -> a) -> f a -> f b
Page: https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
Context: Haskell
Axiom: contramap id = id
Axiom2: contramap (f . g) = contramap g . contramap f
Example: Const a
Predicate
Comparison

Name: Predicate contravariant functor
Definition: contramap g (Predicate p) = Predicate (p . g)
Page: https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
Context: Haskell
Typ: Predicate a = Predicate {getPredicate :: a -> bool}

Name: Predicate contravariant functor
Definition: contramap g (Comparison comp) = Comparison (comp `on` g)
Page: https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
Context: Haskell
Typ: Comparison a = Comparison ( a -> a -> Ordering)

Typ: Profunctor f
Function: dimap ∷ (c → a) → (b → d) → f a b → f c d
Page: https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
Context: Haskell
Axiom: dimap id id = id
Axiom2: dimap (a . b) (c . d) = dimap b c . dimap a d
Intuition: Bifunctor, contravariant in first argument, covariant in second
Example: ->

Question: -> as a profunctor
Answer: dimap contra cov f = cov . f . contra
Page: https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
Context: Haskell