public
Created

Strange parametrized modules vs inheritance behaviour in Erlang

  • Download Gist
a.erl
Erlang
1 2 3 4
-module (a).
-compile (export_all).
 
hello () -> "Hello!".
a.erl_v2
1 2 3 4
-module (a, [X]). %% a.erl with parameters
-compile (export_all).
 
hello () -> "Hello!".
b.erl
Erlang
1 2 3 4 5
-module (b, [Info]).
-compile (export_all).
-extends (a).
 
info () -> Info.
does_not_work.log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
$ 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
modified_a.log
1 2 3 4 5 6 7 8
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!!!
works_pretty_well.log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
$ 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.