Hi José,

the same reasoning would be applicable against having large modules and 
functions, thought no similar restriction exists for these.

There must be then some strong reason for making it hard to have large 
protocols, perhaps of technical one or of another kind, which is not clear.

Anyway, thanks for your response.
Mário Guimarães

quarta-feira, 27 de Fevereiro de 2019 às 17:44:40 UTC, José Valim escreveu:
>
> Protocols do not provide default implementations for functions on purpose, 
> as that would make it easier for developers to write large protocols, while 
> they should attempt to provide protocols that are as minimal as possible, 
> or break large ones into small ones.
>
> So in your case, you can use defdelegate to delegate where you want to (in 
> this case, the Any implementation).
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
>
> On Wed, Feb 27, 2019 at 5:00 AM Mário Guimarães <mario.luis...@gmail.com 
> <javascript:>> wrote:
>
>> Hello,
>>
>> I was trying to make a default implementation of a protocol via
>>
>> defprotocol TheProtocol do
>>    def fun1(...)
>>    def fun2(...)
>>
>> end
>>
>> defimpl TheProtocol, for: Any do
>>    def fun1(...) do
>>    end
>>    def fun2(...) do
>>    end
>> end
>>
>>
>> where "TheProtocol" defines several functions.
>>
>> Then I was trying
>>
>> defimpl TheProtocol, for: Atom do
>>    def fun1(...) do
>>      ...
>>    end
>> end
>>
>>
>> and expecting that when calling
>>
>> TheProtocol.fun2(an_atom, ...)
>>
>> it would invoke the implementation in Any, but instead it complains with 
>> a warning that a fun2 is required but not implemented for Atom.
>>
>> Is it possible to change @fallback_to_true so that it leverages the 
>> functions from Any when these are not implemented in another implementation?
>>
>> To what I am aware of, this should not have semantic effects on existing 
>> applications, because these are providing complete protocol implementations.
>>
>> Thanks
>> Mário
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/eab96901-dc5c-41e8-84bb-e23bda2c2d6a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/eab96901-dc5c-41e8-84bb-e23bda2c2d6a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/fcdaddb8-b84c-4519-9c29-1c5355e097b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to