# Kernel


Freer monad kernel: Return/OpCall ADT with FTCQueue bind, `send`, `map`, `seq`, `pipe`, `kleisli`.

## `bind`

_bind: sequence two computations; if the first is `Pure`, apply `f` to its value; otherwise snoc `f` onto the FTCQueue for O(1) per-step composition._

```
bind : Computation a -> (a -> Computation b) -> Computation b
```

Monadic bind:

```
bind comp f = case comp of
  Pure a     -> f a
  Impure e q -> Impure e (snoc q f)
```

O(1) per bind via FTCQueue snoc (Kiselyov & Ishii 2015, section 3.1).

## `impure`

_impure: re-export of `fx.comp.impure` for kernel consumers._

```
impure : Effect -> FTCQueue -> Computation a
```

Re-export of the computation `Impure` constructor.

## `kleisli`

_kleisli: compose two Kleisli arrows `(a -> M b)` and `(b -> M c)` into a single `(a -> M c)`; the arrow product of the freer-monad Kleisli category._

```
kleisli : (a -> Computation b) -> (b -> Computation c) -> a -> Computation c
```

Kleisli composition. Compose two Kleisli arrows into a single arrow. The associative `>=>` operator in Haskell terminology.

## `map`

_mapComp (exported as `map`): apply `f` to the eventual result of a computation (Functor instance); implemented as `bind comp (x: pure (f x))`._

```
map : (a -> b) -> Computation a -> Computation b
```

Map a function over the result of a computation (Functor instance). Exposed as `map` at the module's top-level.

## `pipe`

_pipe: chain a computation through a list of Kleisli arrows, threading each result into the next via bind; the empty arrow list yields `init` unchanged._

```
pipe : Computation a -> [(a -> Computation b)] -> Computation b
```

Chain a computation through a list of Kleisli arrows. Each arrow's input is the previous arrow's output.

## `pure`

_pure: re-export of `fx.comp.pure` for kernel consumers._

```
pure : a -> Computation a
```

Re-export of the computation `Pure` constructor.

## `queue`

_queue: re-export of the FTCQueue namespace for advanced handler composition and adaptation._

```
queue : Namespace
```

Re-export of `fx.queue` for advanced use.

## `send`

_send: lift an effect request named `name` carrying `param` into a computation suspended at that effect; the handler's response resumes via the continuation queue._

```
send : String -> a -> Computation b
```

Send an effect request. Returns an `Impure` computation whose continuation queue resolves to the handler's response.

## `seq`

_seq: thread a list of computations left-to-right via bind, discarding intermediate values and returning only the last; the empty list yields `pure null`._

```
seq : [Computation a] -> Computation a
```

Sequence a list of computations, threading effects via `bind`. Returns the last result; intermediate values are discarded.

