The Haskell community has developed a number of techniques inspired by category theory, of which monads are best known but should not be confused with monads.
What is the relation between functors in SML and functors in Category theory? Since I don’t know about the details of functors in other languages such as Haskell or OCaml, if there is info of value then please also add sections for other languages.
Asked By : Guy Coder
Answered By : Andrej Bauer
- values are elements of types (example: 42 : int)
- types are elements of Type (example: int : Type)
- ML signatures are kinds (example: OrderedType)
- type constructors are elements of kinds (example: list : Type -> Type)
- ML stuctures are elements of kinds (example: String : OrderedType)
- ML functors are functions between kinds (example: Map.Make : Map.OrderedType -> Make.S)
Now we can draw an analogy between ML and categories, under which functors correspond to functors. But we also notice that datatypes in ML are like “small categories without morphisms”, in other words they are like sets more than they are like categories. We could use an analogy between ML and set theory then:
- datatypes are like sets
- kinds are like set-theoretic classes
- functors are like class-sized functions
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/9769