package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Both For_value.map and For_computation.map involve interacting universally quantified functions. Since OCaml does not support first-class universally quantified functions, so we have to wrap the function in a single-field record (we have done this twice in this module).

The user-supplied mapping function receives:

  • a mapper that it should call to continue descending into the computation/value.
  • possibly an id representing the variable to which the current node will be bound (that is, the current node is either the from field of a subst or the inner field of a store.
  • something called var_from_parent, which is the uid of any type id contained which introduces a value from the immediate parent node. This will be Some if the immediate parent is a Subst, Subst_stateless, or Store node, since those each introduce a new type id into scope. This parameter can be used to build up a mapping from type id to the computation that type id represents.
  • a value passed down from its direct parent. This is not quite the same concept as a fold accumulator, although it is similar (you could think of it as the accumulator for folding over a particular path through the tree.
  • the current node in the tree.

The mapping function should:

  • transform the current node in some way.
  • call the mapper with the its info for the child and the current node.

Note that you could invoke the mapper either before or after transforming the current node (these correspond to post- and pre- order traversal).

type 'from_parent context = {
  1. recurse : 'a. 'from_parent -> 'a Value.t -> 'a Value.t;
  2. var_from_parent : Var_from_parent.t;
  3. parent_path : Bonsai__.Node_path.t Core.Lazy.t;
  4. current_path : Bonsai__.Node_path.t Core.Lazy.t;
}
type 'from_parent user_mapper = {
  1. f : 'a. 'from_parent context -> 'from_parent -> 'a Value.t -> 'a Value.t;
}
val id : 'from_parent user_mapper
OCaml

Innovation. Community. Security.