|
|
|
|
|
by neurotrace
2051 days ago
|
|
I'm trying to wrap my head around this > Even better, you can define relations between the types and do type substitutions, e.g.: to construct this module, you need to give me 2 other modules, each with a specific set of functions, and for which type t1 of the first module, matches type t2 of the second module, while the actual type of t1/t2 does not matter. Isn't this essentially the same as generic type arguments in other languages? Like in this pseudo TypeScript: class CustomModule<T1 extends Module1Interface, T2 extends Module2Interface> {
constructor(t1: T1, t2: T2) { ... }
}
|
|
However, it does serve a similar purpose. For example, if you want to create a datatype for an OrderedList then you'd create a higher-order-module (functor) that receives as an argument another module containing all the necessary comparison functions for the list elements. For example, if you apply the OrderedList functor to the IntOrdering module the result would be an OrderedListOfInt module that provides an abstract data type implementing an ordered list of integers.
In the Ocaml standard library the names would be different but that's the basic idea.