4 ms·
> Even though the OCaml people have a better claim to be using Functor in something resembling its mathematical meaning. I think that is not accurate. Haskell'
by GreaterFool 9y ago
> Even though the OCaml people have a better claim to be using Functor in something resembling its mathematical meaning.
I think that is not accurate. Haskell's notion of a functor is basically taken from category theory. Same with applicative functor. It is easy to draw commutative diagrams for things like `Maybe` or `Either a` to prove it!
In contrast in OCaml functors are module functions. Do modules form categories? Maybe? I haven't seen anyone talking about category of OCaml modules. Perhaps in some papers. But even if they do I wouldn't call OCaml's claim better. When one says Functor in Haskell it is generally understood as "the category theory thing". When one says functor in OCaml I think most people, myself included, would think "module function", whether it satisfies category-theory requirements or not.
Also, worth pointing out that OCaml too has applicative functors. Those are such functors that when applied to same modules produce same types. Whether that fits with the category-theoretic notion of applicative functor... haven't thought about that! Maybe?
Basically
module M1 = Make(F)(G)
module M2 = Make(F)(G)
then if `M1.t` is the same as `M2.t` for some `t` the we have an applicative functor. The other side of the coin are generative functors: each time you apply them they mint new types:
module M1 = Make(F)(G)()
module M2 = Make(F)(G)()
Then `M1.t` /= `M2.t`. This has been introduced in OCaml `4.02`
- eru 9y agoThanks! The main point against Haskell functors being 'proper' is that they only work in the category of 'Hask'.
- LeanderK 9y agowell, there is always: https://github.com/mikeizbicki/subhask https://github.com/mikeizbicki/subhask which provides more flexibility on the categories you are programming in.
- alphaalpha101 9y ago>the category of Hask Which category would that be?
- shakna 9y ago> In contrast in OCaml functors are module functions. Do modules form categories? Wrong kind of functor, I believe. Unfortunately, functor actually refers to a whole heap of different terms in various mathematical fields. Ocaml's functor seems to come from Quine's predicate functor logic, or a related field like combinatory logic.