For me the simplest explanation of a functor F is "a procedure that, given a type, returns a type" (+ some laws which should hold). So Maybe<T> is the functor that, given the type T return the type ?T (aka the set T union the set {null}). List<T> is the functor that, given a type T return the type Array<T> (aka the set of all arrays whose elements are of type T). A functor is not a data structure (e.g. a "container"), is a mapping F between a type T and another type F(T). Now what happens to functions? Given a function f: A -> B, what's F(f)? Here comes the definition of fmap: ((A -> B) -> FA) -> FB. <= this is the usual signature but if you group the arguments as in fmap: (A -> B) -> (FA -> FB) now it should be clear that fmap defines how F maps functions, i.e. what's F(f)
This example makes sense as someone whose studied this at uni, but if you haven't studied an introductory course in category theory this isn't that simple at all. Arrows and mappings are fairly abstract, this isn't a good place to start if the people you're apparently trying to help haven't necessarily seen the notation.
0
u/gcanti Jul 19 '16 edited Jul 19 '16
For me the simplest explanation of a functor
Fis "a procedure that, given a type, returns a type" (+ some laws which should hold). SoMaybe<T>is the functor that, given the typeTreturn the type?T(aka the setTunion the set{null}).List<T>is the functor that, given a typeTreturn the typeArray<T>(aka the set of all arrays whose elements are of typeT). A functor is not a data structure (e.g. a "container"), is a mappingFbetween a typeTand another typeF(T). Now what happens to functions? Given a functionf: A -> B, what'sF(f)? Here comes the definition offmap: ((A -> B) -> FA) -> FB. <= this is the usual signature but if you group the arguments as infmap: (A -> B) -> (FA -> FB)now it should be clear thatfmapdefines howFmaps functions, i.e. what'sF(f)