[erlang-questions] Orthogonality and Principle of least surprise Was: chained functions

Jakob Praher jakob@REDACTED
Wed Feb 1 17:29:35 CET 2012


Am Mittwoch, 01. Februar 2012 15:04 CET, Alisdair Sullivan <alisdairsullivan@REDACTED> schrieb: 
 
> functions in erlang are identified by their name and their arity
> 
> 'F = module:fun()' is ok because the arity, 0, is implied by the arguments
> 
> 'F = module:fun' is not okay because it does not refer to a specific function. you need to tell the compiler which function you wish to call. hence the 'fun module:fun/n' syntax 

IMHO it depends what one is trying to achieve. From an operational point of view I am fine with having a "function reference" as something that can be called if applied with concrete arguments. Hence I do not require a funciton object in the sense that it represents the function itself. 

If one wants to make sure that the right function is targeted one could always write it like: "F = module:fun/N", which is not something I am thinking of.

With the exception of currying, where the arity of the function arguments vs the actual arguments differs, it suffices to just apply the actual arguments to the matching function. 

E.g.  

map([],_) -> [];
map([X|Rest], F) -> [F(X) | map(Rest, F)].

> map([1,2,3], math:square).
[1,4,9]

This is a more lazy / symbolic usage of functions.

Best,
Jakob

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
 
 
 
 




More information about the erlang-questions mailing list