package travesty

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

Mapping for containers with two element types.

Bi_mappable implements the Haskell notion of a bifunctor: a container that contains two distinct element types, both of which can be non-monadically, covariantly mapped over.

Common examples include:

  • associative lists, where the two types are keys and values;
  • result types, where the two types are success and failure.

Signatures

Bi_mappable_intf contains the signatures for Bi_mappable.

include module type of Bi_mappable_intf

The generic signature

As with Traversable, we define the signature of bi-mappable structures in an arity-generic way, then specialise it for the various arities.

module type Generic = sig ... end

Generic describes bi-mapping on any arity of type.

Basic signatures

The basic signatures are S0, which defines mapping across an arity-0 type t (with a fixed, associated element type elt); S1_left and S1_right, which fix the right and left element type respectively (leaving the named type floating); and S2, which defines mapping across an arity-2 type ('l, 'r) t with left element type 'l and right element type 'r.

module type S0 = sig ... end

S0 is the signature of an arity-0 bi-mappable type.

module type S1_left = sig ... end

S1_left is the signature of an arity-1 bi-mappable type with a floating left type and fixed right type.

module type S1_right = sig ... end

S1_right is the signature of an arity-1 bi-mappable type with a floating right type and fixed left type.

module type S2 = sig ... end

S2 is the signature of an arity-2 bi-mappable type with floating left and right types.

Extensions

The signatures below describe various functions we can derive from bi-mappable types and mappable containers. To apply them to existing types, use the functors in Bi_mappable.

module type Generic_extensions = sig ... end

Generic_extensions describes extensions that apply to all arities, in an arity-neutral manner.

module type Extensions0 = sig ... end

Extensions for arity-0 bi-mappable containers.

module type S0_with_extensions = sig ... end

Combines S0 and Extensions0.

module type Extensions1_left = sig ... end

Extensions for arity-1 bi-mappable containers with a floating left type.

module type S1_left_with_extensions = sig ... end
module type Extensions1_right = sig ... end

Extensions for arity-1 bi-mappable containers with a floating right type.

module type S1_right_with_extensions = sig ... end
module type Extensions2 = sig ... end

Extensions2 describes various extensions of arity-1 mappable containers.

module type S2_with_extensions = sig ... end

Combines S2 and Extensions2.

Extending bi-mappable containers

We define several derived functions for bi-mappable containers in Bi_mappable_intf---here, we define functors to generate them.

module Extend2 (S : S2) : Extensions2 with type ('l, 'r) t := ('l, 'r) S.t

Extend2 implements Extensions2 for an arity-2 bi-mappable container.

module Extend1_left (S : S1_left) : Extensions1_left with type 'l t := 'l S.t and type right := S.right

Extend1_left implements Extensions1_left for an arity-1 bi-mappable container with floating left type.

module Extend1_right (S : S1_right) : Extensions1_right with type 'r t := 'r S.t and type left := S.left

Extend1_right implements Extensions1_right for an arity-1 bi-mappable container with floating right type.

module Extend0 (S : S0) : Extensions0 with type t := S.t and type left := S.left and type right := S.right

Extend0 implements Extensions0 for an arity-0 bi-mappable container.

OCaml

Innovation. Community. Security.