[erlang-questions] What is the purpose of the fun vs function distinction?
Robert Virding
rvirding@REDACTED
Sun Jan 13 23:28:17 CET 2008
On 13/01/2008, Christian S <chsu79@REDACTED> wrote:
>
> 2008/1/13 David Cabana <drcabana@REDACTED>:
> > Well, things are what they are. Erlang simply does not have the clean
> syntax
> > of scheme or Haskell with respect to passing functions as arguments. But
> > why? Is this merely cruft, or does it serve some purpose?
>
> Funs were added later on to erlang, that can explain why they do not have
> more
> convenient syntax. So "cruft" by your taxonomy I guess.
There is one feature of Erlang which seriously screws up the handling of
functions compared to Scheme and Haskell, and that is having functions with
the same name but with different arities. This means that there is no clear
binding function <-> name which you need to be able to write as you can in
the other languages. To refer to a function you need both the name and the
arity. Period. The same with exported functions, to refer to a function in
another module you need the module name, the function name and its arity.
That is why you have a construction fun to create a function reference, it
contains the arity within it. The "fun name/arity" syntax is really just a
short form for:
fun (A1, ..., An) -> name/A1, ..., An) end.
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080113/82db2e63/attachment.htm>
More information about the erlang-questions
mailing list