Hacker News new | ask | show | jobs
by kyllo 3875 days ago
What do you mean by "without functors?" F# doesn't have a way to define a `map` function that is generalizable to arbitrary data types?
1 comments

OCaml functors are not the same thing as Haskell functors — in OCaml they refer to mappings from modules to modules.

https://realworldocaml.org/v1/en/html/functors.html

"Functor" might just be the most overloaded term in computer programming... Just of the top of my head it has totally different meanings in Ocaml, Haskell and C++.
They're not totally different between OCaml and Haskell. They're based on the same concept from Category Theory: a mapping of objects and morphisms from one category to another. It's just that Haskell functors are at the type level and OCaml's functors are at the module level.

Apparently F# has support for neither style of functor--it doesn't have parametric modules and it also doesn't have typeclasses. So in F# `map` is defined independently for each type:

   Set.map : ('a -> 'b) -> 'a Set -> 'b Set 
   Seq.map : ('a -> 'b) -> 'a seq -> 'b seq 
   List.map : ('a -> 'b) -> 'a list -> 'b list 
   Array.map : ('a -> 'b) -> 'a [] -> 'b []