38 ms·
> >In OCaml, “Functor” is a well-defined term with a completely different meaning > No, it has the same meaning. It does not behave identically because the lan
by more_original 10y ago
> >In OCaml, “Functor” is a well-defined term with a completely different meaning
> No, it has the same meaning. It does not behave identically because the languages do not have identical designs.
Functors in Haskell and OCaml are different things. Haskell Functors correspond to the category-theoretic notion of a functor (a thing mapping objects to objects and morphisms to morphisms in a reasonable manner). In OCaml and ML, Functors represent parameterized modules. These are not known to correspond to category-theoretic functors in any reasonable way (and there have been proposals for category-theoretic models of the ML module system). I guess the term Functor is a bit of a misnomer in the ML-like languages.
- MustardTiger 10y ago>In OCaml and ML, Functors represent parameterized modules No, functors represent functions from a module to a module. Oh hey, that sounds just like the standard definition of a functor. As I said, the behavior is different because the languages are different, but both are named after the category theory functor, because they both emulate it.
- more_original 10y agoPlease read up on the ML module system and its origins. http://cs.stackexchange.com/questions/9769/what-is-the-relation-between-functors-in-sml-and-category-theory http://cs.stackexchange.com/questions/9769/what-is-the-relat... Functors play very different roles in Haskell and OCaml/ML. In Haskell, the Functor class is there to implement the functoriality of a type. If F is a functor, then one implements maps of type F A -> F B from given A -> B in a functorial way. In ML, the term functor was chosen because they are not first-class functions, but "a level up" (much like a functor is a level up from the maps in the category that it operates on). However, if F is an ML functor, then there are no "maps" between the modules F(A) and F(B). The morphism part, which is the essence of a Functor in Haskell, is missing in ML. This is why I think that the functor terminology isn't very good in ML. Not everything that maps one thing to another is a functor.
- MustardTiger 10y ago>However, if F is an ML functor, then there are no "maps" between the modules F(A) and F(B). Yes there is, the functor. Just repeating a false statement won't make it come true.
- more_original 10y ago> Yes there is, the functor. What we have is a functor F, which would be defined as in: module F = functor (X: S) -> .... If you have two modules A and B of signature S, then you can form F(A) and F(B) and these are both modules. Now where are the maps from F(A) to F(B)? Just saying "the functor" does not explain this. > Just repeating a false statement won't make it come true. Exactly!
- MustardTiger 10y agoI can't teach you ocaml on hn. If you want to learn, try this: https://realworldocaml.org/ https://realworldocaml.org/
- more_original 10y agoOk, so you can't (or don't want to) actually back up your claim that OCaml functors have the same meaning as functors in Haskell. Which is to be expected, because it's bogus. I know OCaml fairly well. The reason you can't show me the map from F(A) to F(B) is that it's not there. If you want to claim a relation between OCaml functors and category-theoretic functors, then you must be able to justify your claims. Saying "functors represent functions from a module to a module. Oh hey, that sounds just like the standard definition of a functor." is just not a convincing argument.
- MustardTiger 10y ago>The reason you can't show me the map from F(A) to F(B) is that it's not there. That is literally the functor. Seriously, read the chapter on modules.