[erlang-questions] currying and lazy evaluation questions

John Hughes <>
Tue Sep 23 07:14:14 CEST 2008


> I read a note on the Internet that said "You can do lazy evaluation in 
> Erlang (observe Erlang QuickCheck), but you have to be explicit about it."
> ?
> Can some one explain to me how to "explicitly" use lazy evaluation in 
> Erlang, in the general?
> ?

I use macros

-define(DELAY(E),fun()->E end).
-define(FORCE(F),F()).

to save a little typing, and more importantly mark the places where I'm 
thinking in terms of laziness. In my experience this is pretty tedious (lots 
of syntactic noise) and error-prone (easy to forget to FORCE or DELAY 
somewhere)--and as Richard pointed out, inefficient if you FORCE the same 
value more than once, so you basically can only use the idea where lazy 
data-structures are going to be consumed once only.

I certainly wouldn't recommend transliterating Haskell code and inserting 
DELAY and FORCE everywhere to get the same semantics--that would be very 
heavyweight, and often unnecessary. But in those cases where you really need 
lazy evaluation, it's a useful technique.

John 




More information about the erlang-questions mailing list