std.applicative

Implementation of the Applicative type

Types

type Applicative f = {
    functor : std.functor.Functor f,
    apply : forall a b . f (a -> b) -> f a -> f b,
    wrap : forall a . a -> f a
}

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <> u <> v <> w = u <> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <> wrap y = wrap (\g -> g x) <> u

Values

let apply ?app : forall b a f . [std.applicative.Applicative f] -> f (a -> b) -> f a -> f b

Like functor.map, but this time the supplied function is embedded in f

Note
  • Known as (<*>) in Haskell

let wrap ?app : forall a f . [std.applicative.Applicative f] -> a -> f a

Wrap the supplied value in f

Examples
  • option.applicative.wrap 1 == Some 1
  • result.applicative.wrap 1 == Ok 1
  • list.applicative.wrap 1 == list.of [1]
Note
  • Known as pure in Haskell

let <*> : forall b a f . [std.applicative.Applicative f] -> f (a -> b) -> f a -> f b

Alias of <*>

let <* l r : forall b a f . [std.applicative.Applicative f] -> f a -> f b -> f a

Sequence actions, discarding the value of the second argument

let *> l r : forall b a f . [std.applicative.Applicative f] -> f a -> f b -> f b

Sequence actions, discarding the value of the first argument

let map2 fn a b : forall c b a f .
    [std.applicative.Applicative f] -> (a -> b -> c) -> f a -> f b -> f c

Maps over two actions

let map3 fn a b c : forall d c b a f .
    [std.applicative.Applicative f]
        -> (a -> b -> c -> d)
        -> f a
        -> f b
        -> f c
        -> f d

Maps over three actions

let map4 fn a b c d : forall a a0 a1 a2 a3 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3

let map5 fn a b c d e : forall a a0 a1 a2 a3 a4 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4

let map6 fn a b c d e f : forall a a0 a1 a2 a3 a4 a5 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4 -> a5)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4
        -> f a5

let map7 fn a b c d e f g : forall a a0 a1 a2 a3 a4 a5 a6 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4
        -> f a5
        -> f a6

let map8 fn a b c d e f g h : forall a a0 a1 a2 a3 a4 a5 a6 a7 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4
        -> f a5
        -> f a6
        -> f a7

let map9 fn a b c d e f g h i : forall a a0 a1 a2 a3 a4 a5 a6 a7 a8 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4
        -> f a5
        -> f a6
        -> f a7
        -> f a8

let map10 fn a b c d e f g h i j : forall a a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 .
    forall f .
    [std.applicative.Applicative f]
        -> (a -> a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9)
        -> f a
        -> f a0
        -> f a1
        -> f a2
        -> f a3
        -> f a4
        -> f a5
        -> f a6
        -> f a7
        -> f a8
        -> f a9

let when b m : forall m . [std.applicative.Applicative m] -> std.types.Bool -> m () -> m ()