3 ms·
One of the things that I really love about Erlang, is that it unrolls loops and recursion like: count_to_ten(n) -> count_to_ten(n+1); count_to_ten(10)
by fao_ 9y ago
One of the things that I really love about Erlang, is that it unrolls loops and recursion like:
count_to_ten(n) ->
count_to_ten(n+1);
count_to_ten(10) ->
done.
which is much cleaner than how the same code is presented in 99% of functional programming languages.
- fbonetti 9y agoThat's just a combination of pattern matching and tail call optimization. That code would look exactly this same in Haskell: countToTen n = countToTen (n + 1) countToTen 10 = done
- dllthomas 9y agoThe 10 case would have to be first, or that's an infinite loop. Cases are checked in order. That said, the compiler will give you a warning about it.