pi3ce has quit [Read error: Connection reset by peer]
pi3ce has joined #ocaml
bartholin has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
Guest56 has quit [Quit: Client closed]
gentauro has quit [Read error: Connection reset by peer]
gentauro has joined #ocaml
spynxic has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
<discocaml_>
<diligentclerk> It's nonsense. A list is not a functor. The list type constructor List.t is a functor.
alexherbo2 has joined #ocaml
<olle>
diligentclerk, you know the haskell lingo too?
<olle>
I think even C++ has its own def of "functor"
alexherbo2 has quit [Remote host closed the connection]
<discocaml_>
<diligentclerk> I actually came to OCaml via mathematics and formal logic, so I know some of this language from mathematics. I haven't programmed in Haskell.
Haudegen has joined #ocaml
<olle>
Mm ok, thanks :)
<discocaml_>
<diligentclerk> The Haskell usage of "functor" is the closest to category theory, IMO. It can be taken literally.
<discocaml_>
<diligentclerk> I suspect OCaml functors are named by analogy with category theory, because functors are functions that send "big objects" (modules, types) to "big objects", by contrast with ordinary value-level functions between types. This is a good metaphor even if module functors aren't "mappable" in the sense that the List.t type constructor is.
<discocaml_>
<diligentclerk> If I had to guess, from skimming the C++ def, they are borrowing the word "functor" from Carnap and it has nothing to do with category theory.
<discocaml_>
<diligentclerk> A Haskell functor is any module implementing the signature `sig type 'a t val map : ('a -> 'b) -> ('a t -> 'b a) end`.
<olle>
diligentclerk, oh that's not too far off from original comment!
<olle>
But completely different from OCaml usage
<discocaml_>
<diligentclerk> Yes.
<discocaml_>
<diligentclerk> An example of a polymorphic type constructor which is not a functor is `'type 'a t = 'a -> 'a`.
<discocaml_>
<diligentclerk> But, very many polymorphic type constructors are indeed functors
<olle>
Got it
<discocaml_>
<diligentclerk> I guess to expand a bit, there are a few closely related signatures whose modules I would also call functors, such as:
<discocaml_>
<diligentclerk>
<discocaml_>
<diligentclerk> `sig type ('a, 'b, 'c) t
<discocaml_>
<diligentclerk> val map : ('a0 -> 'a1) -> ('b0 -> 'b1) -> ('c0 -> 'c1) -> ('a0, 'b0, 'c0) t -> ('a1, 'b1, 'c1) t end`
<discocaml_>
<diligentclerk>
<discocaml_>
<diligentclerk> and so-called "contravariant functors" of module type
<discocaml_>
<diligentclerk> `sig type 'a t
<discocaml_>
<diligentclerk> val map ('b -> 'a) -> 'a t -> 'b t`
<discocaml_>
<diligentclerk> for example, `type 'a t = 'a -> int` is a contravariant functor.
<Putonlalla>
That is a good explanation, but I want to point out that (1) the mapping has to obey some laws to qualify as a functor implementation and (2) a type can sometimes admit more than one lawful functor implementation.
hwj has joined #ocaml
hwj has quit [Client Quit]
<discocaml_>
<yawaramin> olle: 'Even in Haskell parlour, this must be nonsense.' where is it from?
<olle>
yawaramin, ah just some guy on /r/php subreddit
<olle>
or girl
<discocaml_>
<yawaramin> Crell by any chance?
<olle>
yawaramin, nah, Crell would know better I think ^^