[erlang-questions] Generators?

Richard Carlsson <>
Tue Jul 31 18:27:57 CEST 2007

James Hague wrote:
>> But the problem is that these abstractions, or
>> at least the combination of them, are slower than a hand-coded
>> function explicit recursion function. So, is there any way to make the
>> natural abstractions work as fast as the hand-coded version?
> It's interesting that list comprehensions are compiled into code that
> acts the same as hand-coded functions, but uses of similar functions
> like lists:foldl, lists:flatmap, and lists:partition are not.

Actually, there is a compiler option (undocumented, I think)
'inline_list_funcs' that creates inline versions of the most common
higher order list functions. It's not well tested, though, so there may
be some lurking bugs. Since it is a semantic-changing optimization
(inlines hard knowledge of the semantics of functions in another module)
it is not turned on by default and has been regarded with some suspicion
by OTP. Do make some noise if you want it to be a documented feature.

In combination with the generic inliner (the 'inline' option), it should
be able to produce code similar to the corresponding hand-coded
functions in cases where the fun is provided explicitly. (Try increasing
the {inline_size, N} and/or {inline_effort, N} values if not.)

Hint: use the 'to_cerl' flag to inspect the resulting code.


More information about the erlang-questions mailing list