package alg_structs
Module Alg_structs.FunctorSource
An interface for types that can be mapped over.
All you need to know to use this module effectively:
given type 'a t, function map : f:('a -> 'b) -> 'a t -> 'b t will map f "over" t by taking a value of type 'a t to a value of type 'b t.
E.g., if
type 'a t = int listthen
map ~f:Int.to_string : int t -> string tis a function which maps int lists to string lists, so
map ~f:Int.to_string [1;2;3] = ["1";"2";"3"]A Rough Sketch of the Category Theoretic Basis
To repeat, you don't need to read any of the following in order to make use of this module.
The use of the word functor in this context refers to the category theoretic concept of Functor, which is a map between categories. A functor F: C -> D that maps category C to category D consists of two mappings:
- a mapping of each object in
Cto some object inD - a mapping of each arrow in
Cto some arrow inD
These mappings must respect the Laws.
An "endofunctor" is a functor that is a map of one category within itself (or back onto itself).
We imagine a category CAML (analogous to Hask), where the objects are OCaml types and the arrows are functions between those types. S then specifies an interface for modules that implement an "endofunctor" on CAML, mapping types to types and functions to functions.
Seed
Interface for a mappable type with an unlabeled map function.
Interface
Laws
Law notes the laws that should be obeyed by any instantiation of Functor in the form of predicates that should be true for any arguments of the appropriate type.
Constructors
Module functors and signatures for expediting instantiation of Functors.
MakeUnlabeled makes an module instantiating S, with a labeled S.map, out of a module instantiating UnlabeledSeed with an unlabeled map function.