<div dir="ltr">I have seen this question asked earlier in Stack Overflow and answered it there: <a href="http://stackoverflow.com/questions/20556472/elixir-protocols-in-erlang-a-strange-warning/20561973#20561973">http://stackoverflow.com/questions/20556472/elixir-protocols-in-erlang-a-strange-warning/20561973#20561973</a><div>

<br></div><div>I have also reported a bug to erlang-bugs this time.</div><div><br></div><div><div class="gmail_extra"><div class="gmail_quote">One final note: although parameterized modules were removed from R16, the underlying dispatch mechanism, which is used in the descried issue, is not deprecated and it won't be removed.</div>

<div><br></div></div></div></div><div class="gmail_extra"><br clear="all"><div><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div>

<div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div>

</div>
<br><br><div class="gmail_quote">On Fri, Dec 13, 2013 at 8:10 AM, Dmitry Kolesnikov <span dir="ltr"><<a href="mailto:dmkolesnikov@gmail.com" target="_blank">dmkolesnikov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word">Hello,<div><br></div><div>Essentially you are trying to use parametrized modules, which get deprecated in R14/15 and dropped from R16.</div><div>See for details: </div><div> * <a href="http://www.erlang.org/news/35" target="_blank">http://www.erlang.org/news/35</a></div>

<div> * <a href="http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf" target="_blank">http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf</a></div><div><br></div><div>This type of problems are solvable either via pattern match or currying:</div>

<div><br></div><div><div>-module(stringer).</div><div>-export([stringer/1,sample/0]).</div><div><br></div><div>stringer(V) when is_list(V) -></div><div>    fun() -> to_string(V, nop) end;</div><div>stringer(V) when is_atom(V) -></div>

<div>    fun() -> to_string(V, nop) end;</div><div>stringer(_V) -></div><div>    fun() -> not_implemented end.</div><div class="im"><div><br></div><div>to_string(V, _Nop) -></div><div>    Buffer = io_lib:format("~p",[V]),</div>

<div>    lists:flatten(Buffer).</div><div><br></div><div>sample() -></div></div><div>    io:format("~p~n", [(stringer([1,2]))()]),</div><div>    io:format("~p~n", [(stringer(cute_atom))()]),</div><div>

    io:format("~p~n", [(stringer(13))()]).</div></div><div><br></div><div><br></div><div>Best Regards,</div><div>Dmitry</div><div><br><div><div><div class="h5"><div>On Dec 13, 2013, at 8:31 AM, Kaveh Shahbazian <<a href="mailto:kaveh.shahbazian@gmail.com" target="_blank">kaveh.shahbazian@gmail.com</a>> wrote:</div>

<br></div></div><blockquote type="cite"><div><div class="h5"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">I <span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px">wanted to write something like</span><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px"> </span><code style="font-size:14px;line-height:18px;margin:0px;padding:1px 5px;border:0px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">((IStringer)object).ToString()</code><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px"> </span><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px">(in C#) in Erlang. After some studying I've learnt that Elixir has something called Protocols that pretty much resembles the same thing of C# (in an inside-out manner). Then I came up with this idea/code in Erlang - which is nice enough to me like:</span></div>


<div class="gmail_default" style="font-family:verdana,sans-serif"><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px"><br></span></div>
<pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;line-height:18px">

<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">?stringer(my_val):to_string().
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">
And it either returns the expected value or <code style="margin:0px;padding:1px 5px;border:0px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">not_implemented</code> atom!</p>

<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">But 2 questions:</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">

1 - Why nobody use this or promote things based on stateful modules in Erlang? (OTP aside and from talking to some Erlangers they did not know that actually OTP is built around this! So really there is a need to change how Erlang is being taught and promoted. It's possible that I am confused.).</p>

<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">2 - Why I get this warning? That call actually never fails.</p>

<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">The warning:</p>
<pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;line-height:18px">

<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">stringer.erl:18: Warning: invalid module and/or function name; this call will always fail
stringer.erl:19: Warning: invalid module and/or function name; this call will always fail
stringer.erl:20: Warning: invalid module and/or function name; this call will always fail
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">
The code:</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;line-height:18px">

<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">-module(stringer).
-export([to_string/1,sample/0]).

-define(stringer(V), {stringer, V}).

to_string({stringer, V}) when is_list(V) ->
    to_string(V, nop);
to_string({stringer, V}) when is_atom(V) ->
    to_string(V, nop);
to_string({stringer, _V}) ->
    not_implemented.

to_string(V, _Nop) ->
    Buffer = io_lib:format("~p",[V]),
    lists:flatten(Buffer).

sample() ->
    io:format("~p~n", [?stringer([1,2]):to_string()]),
    io:format("~p~n", [?stringer(cute_atom):to_string()]),
    io:format("~p~n", [?stringer(13):to_string()]).
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;clear:both;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px">
And the output is:</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;line-height:18px">

<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">"[1,2]"
"cute_atom"
not_implemented</code></pre>
</div></div></div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>

</blockquote></div><br></div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>