Yes there is a technical reason, if you call the function member/0 in your module, how should the compiler know which module you intented to call? The imported one or the one declared in your module?<br><br>Overriding is not possible in Erlang at the moment. Although there was a presentation on the subject (and others) and the Erlang User Conference (EUC) this year:
<a href="http://www.erlang.se/euc/07/papers/1700Carlsson.pdf">http://www.erlang.se/euc/07/papers/1700Carlsson.pdf</a><br><br>One simple way to "solve" your problem though is to just not import the member/0 function in the module you want to override it in. This way both module will have the member/0 function anyway. Thus you have to tell the modules that are not to override it to import the template function instead.
<br><br><br>Cheers,<br>Adam<br><br><div class="gmail_quote">On Dec 6, 2007 6:49 AM, Robin <<a href="mailto:robi123@gmail.com">robi123@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
lw_template.erl:<br><div class="Ih2E3d">-module(lw_template).<br>-compile(export_all).<br>member() -> template.<br><br></div>lw_special.erl:<br><div class="Ih2E3d">-module(lw_special).<br>-compile(export_all).<br>-import(lw_template, [member/0]).
<br>member() -> special.<br><br></div>The error output:<br><div class="Ih2E3d">Eshell V5.5.5 (abort with ^G)<br></div>1> lw_special:member().<br>** exited: {undef,[{lw_special,member,[]},<br><div class="Ih2E3d"> {erl_eval,do_apply,5},
<br> {shell,exprs,6},<br> {shell,eval_loop,3}]} **<br><br></div>Is there any technical reason that you cannot override an imported<br>function?<br><br>Thanks,<br><br>Robin<br><div><div>
</div><div class="Wj3C7c"><br><br>On Dec 5, 7:41 pm, Robin <<a href="mailto:robi...@gmail.com">robi...@gmail.com</a>> wrote:<br>> This is a simple example using -import:<br>><br>> -module(lw_template).<br>> -compile(export_all).
<br>> member() -> template.<br>><br>> -module(lw_special).<br>> -compile(export_all).<br>> -import(lw_template, [member/0]).<br>> member() -> special.<br>><br>> When I import member/0 and then override it, the compiler gives the
<br>> warning:<br>><br>> lw_special.erl: defining imported function member/0<br>><br>> When I call member/0, the runtime bombs with an error:<br>><br>> Eshell V5.5.5 (abort with ^G)<br>> 1> ls_special:member().
<br>> ** exited: {undef,[{ls_special,member,[]},<br>> {erl_eval,do_apply,5},<br>> {shell,exprs,6},<br>> {shell,eval_loop,3}]} **<br>><br>> Import followed by override does not work above, so how else can you
<br>> specialize an imported function at compile time?<br>><br>> If the runtime bombs from overriding a function, then should the<br>> compiler produce an error rather than just a warning?<br>><br>> thanks,
<br>><br>> Robin<br>><br>> _______________________________________________<br>> erlang-questions mailing list<br></div></div>> erlang-questi...@erlang.orghttp://www.erlang.org/mailman/listinfo/erlang-questions
<br><div><div></div><div class="Wj3C7c">_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">
http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></div></div></blockquote></div><br>