Skip to content

Instantly share code, notes, and snippets.

@ztmr
Created October 6, 2012 21:18
Show Gist options
  • Save ztmr/3846164 to your computer and use it in GitHub Desktop.
Save ztmr/3846164 to your computer and use it in GitHub Desktop.
Strange parametrized modules vs inheritance behaviour in Erlang
-module (a).
-compile (export_all).
hello () -> "Hello!".
-module (a, [X]). %% a.erl with parameters
-compile (export_all).
hello () -> "Hello!".
-module (b, [Info]).
-compile (export_all).
-extends (a).
info () -> Info.
$ erl
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1>
1>
1> a:module_info ().
[{exports,[{hello,0},{module_info,0},{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[270635781666670138481523990332392551879]}]},
{compile,[{options,[{outdir,"/home/hobby/test"}]},
{version,"4.8.2"},
{time,{2012,10,6,20,59,15}},
{source,"/home/hobby/test/a.erl"}]}]
2> b:module_info ().
[{exports,[{new,1},
{instance,2},
{info,1},
{module_info,0},
{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[54970594216433541512496372856475307087]},
{abstract,[true]},
{extends,[a]}]},
{compile,[{options,[{outdir,"/home/hobby/test"}]},
{version,"4.8.2"},
{time,{2012,10,6,20,59,15}},
{source,"/home/hobby/test/b.erl"}]}]
3> a:hello().
"Hello!"
4> b:new ("World").
** exception error: undefined function a:new/1
in function b:new/1
5> q().
ok
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> b:new ("foo").
{b,{a,"foo"},"foo"}
...this (a.erl_v2) works, but it's very strange!!!
$ erl
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [async-threads:0] [kernel-poll:false]
Eshell V5.9.1 (abort with ^G)
1> a:module_info ().
[{exports,[{hello,0},{module_info,0},{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[270635781666670138481523990332392551879]}]},
{compile,[{options,[{outdir,"/home/tmr/test"}]},
{version,"4.8.1"},
{time,{2012,10,6,20,55,42}},
{source,"/home/tmr/test/a.erl"}]}]
2> b:module_info ().
[{exports,[{new,1},
{instance,1},
{info,1},
{module_info,0},
{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[50133246433396715275574202450786346567]},
{abstract,[true]},
{extends,[a]}]},
{compile,[{options,[{outdir,"/home/tmr/test"}]},
{version,"4.8.1"},
{time,{2012,10,6,20,55,42}},
{source,"/home/tmr/test/b.erl"}]}]
3> a:hello().
"Hello!"
4> b:new ("World").
{b,"World"}
5> (b:new ("World")):info ().
"World"
6> q().
ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment