[erlang-questions] Orthogonality and Principle of least surprise Was: chained functions
Robert Virding
robert.virding@REDACTED
Wed Feb 1 22:47:16 CET 2012
The problem with your reasoning is that your "functional reference" may refer to many functions. Functions with the same name and a different arity are DIFFERENT functions, one reference cannot refer to them. It is like expecting the "reference" F = module:big also to call not just the function 'big' but also the function 'big_name' because they have the same prefix. They ARE different functions which just happen to have the same name.
Robert
----- Original Message -----
>
> 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
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list