On this page:
gen:  monad
monad?
bind
mdo
:  =
8.0

27 Monads

 (require xiden/monad) package: xiden

xiden/monad provides a limited interface for monads. Includes only a monomorphic bind and a notation for composition.

syntax

gen:monad

A generic interface for monad types.

Only includes bind to date.

Returns #t if the argument implements gen:monad.

procedure

(bind ma lift)  monad?

  ma : monad?
  lift : (-> any/c monad?)
Returns a monadic value that composes ma with the monadic value returned from lift.

Use to compose two functions that each deal with a monadic type.

syntax

(mdo step ...)

 
step = expr
  | id := expr
A “monadic do” form for composing a sequence of steps using bind operations.

In the simplest case, (eq? (mdo V) V). Once more than one term is available, each term must be of the same monadic type. In other words, mdo is monomorphic.

:= is the monadic bind operator. Here’s an example in terms of logged procedures:

(mdo number := (logged-unit 1)
     number)

syntax

:=

Binds an expression on the right hand side to an identifier on the left hand side in the context of mdo.

Raises an error when used outside of mdo. Since package outputs use implicit mdo forms, := may also appear within them.