After your excelent suggestions for names
(makeMapper and makeGetter, they make everything easier, thank you),
I'll try answering this, with a F#-like syntax using redundant parentheses
around arguments to make them more explicit
to those who don't know F#
Let's suppose map is defined as:
> let map (aList) (aFunction) = ...something here...
Read the above as: makeMapper is a function just like applyLast,
but the first argument (to applyLast) is already provided, being "map".
The functionality of applyFirst is implicit when the
remanining parameters are missing, so we only need applyLast.
So makeMapper is called as
> let mapperWithAGetter = makeMapper (aGetter)
This completes the call to applyLast,
so now we have a (fun (x) -> map (x) (aGetter))
Now we only need to bind x. The result is called like this
> mapperWithAGetter (aList)
IMO, all of this could've been written as:
> let makeMapper (aGetter) = fun (aList) -> map (aList) (aGetter)
Or:
> let makeMapper (aGetter) (aList) = map (aList) (aGetter)
Read both as: makeMapper takes aGetter and returns
a function which takes aList
Notice that everything would be much easiear if map took aFunction
as its first parameter:
> let map (aFunction) (aList) = ...
> let makeMapper = map // duh
Remember that partial application is implicit!
It would also be easier if applyLast had better syntax,
using _ for the missing parameter (the first), as in this
Scala-like snippet:
Let's suppose map is defined as:
> let map (aList) (aFunction) = ...something here...
(this is according to https://github.com/raganwald/allong.es/blob/master/README.md which seems to have the parameters reversed when compared to F#'s Seq.map, Lis.map, etc.)
And let's suppose applyLast is defined as:
> let applyLast (aFunction) (anArgument) = (fun (x) -> aFunction (x) (anArgument))
So makeMapper is:
> let makeMapper = applyLast (map)
Read the above as: makeMapper is a function just like applyLast, but the first argument (to applyLast) is already provided, being "map". The functionality of applyFirst is implicit when the remanining parameters are missing, so we only need applyLast.
So makeMapper is called as
> let mapperWithAGetter = makeMapper (aGetter)
This completes the call to applyLast, so now we have a (fun (x) -> map (x) (aGetter))
Now we only need to bind x. The result is called like this
> mapperWithAGetter (aList)
IMO, all of this could've been written as:
> let makeMapper (aGetter) = fun (aList) -> map (aList) (aGetter)
Or:
> let makeMapper (aGetter) (aList) = map (aList) (aGetter)
Read both as: makeMapper takes aGetter and returns a function which takes aList
Notice that everything would be much easiear if map took aFunction as its first parameter:
> let map (aFunction) (aList) = ...
> let makeMapper = map // duh
Remember that partial application is implicit!
It would also be easier if applyLast had better syntax, using _ for the missing parameter (the first), as in this Scala-like snippet:
> def makeMapper(aGetter: Any => Any): List[Any] => List[Any] = { _.map(aGetter) }
(I guess Haskell has some nice syntax for this too, but I don't think F# has anything like this)
All of this was not easy to get right, I hope I didn't make any mistake regarding the position and number of parameters.