Hidden Features of Erlang

pageman picture pageman · Jun 30, 2009 · Viewed 10.4k times · Source

In the spirit of:

  • Hidden Features of C#
  • Hidden Features of Java
  • Hidden Features of ASP.NET
  • Hidden Features of Python
  • Hidden Features of HTML
  • and other Hidden Features questions

What are the hidden features of Erlang that every Erlang developer should be aware of?

One hidden feature per answer, please.

Answer

bjnortier picture bjnortier · Jul 6, 2009

Inheritance! http://www.erlang.se/euc/07/papers/1700Carlsson.pdf

Parent

-module(parent).
-export([foo/0, bar/0]).

foo() ->
    io:format("parent:foo/0 ~n", []).

bar() ->
    io:format("parent:bar/0 ~n", []).

Child

-module(child).
-extends(parent).
-export([foo/0]).

foo() ->
    io:format("child:foo/0 ~n", []).

Console

23> parent:foo().
parent:foo/0 
ok
24> parent:bar().
parent:bar/0 
ok
25> child:foo().
child:foo/0 
ok
26> child:bar().
parent:bar/0 
ok