[erlang-questions] DRY principle and the syntax inconsistency in fun vs. vanilla functions

Richard O'Keefe ok@REDACTED
Fri May 20 10:36:00 CEST 2011


On 19/05/2011, at 4:21 AM, Michael Turner wrote:

> "Anyway, it is often a good idea to break funs out into full functions to reduce nesting and facilitate tracing.  Lots of funs make programs hard to debug."
> 
> I agree. On both points. But neither point is really relevant to my case here. I'm not proposing that people write more funs. I'm proposing that writing named functions enjoy one of the syntactic benefits of funs.

Don't you mean "costs", "prices", "curses", or something like that?

In Haskell, my personal style book says "don't write anonymous functions,
because you will never remember what they mean without a name."
That works because
 - Haskell has list comprehensions, so a common need for anonymous
   functions in SML just goes away (Erlang has them too)
 - Haskell lets you nest ordinary functions one inside another

If you want to snipe at Erlang syntax, complain about the fact that
we cannot write

f(...) ->
    let fun g(...) -> ...;
            g(...) -> ...
        end,
        fun h(...) -> ...;
            h(...) -> ...
        end
    in ... g(...) ... h(...) ...

as an analogue of Haskell's

	f ... = ... g ... h ...
	  where g ... = ...
		g ... = ...
		h ... = ...
		h ... = ...

No, I am not proposing this or any other syntax for the purpose, just
noting that where I would use a fun in Erlang, I *don't* use an
anonymous function in Haskell, precisely so that I can give it a name.
(And this is despite trying to use point-free style more.)





More information about the erlang-questions mailing list