Hi

Perhaps the error message for an unimplemented protocol could be made more
friendly. I don't have any suggestions myself, but perhaps Edouard had some
ideas for Map.drop that could be generalised to all protocols.

Cheers,
Louis

On Sun, 13 Jan 2019, 12:02 José Valim, <jose.va...@plataformatec.com.br>
wrote:

> It would be possible only if you manually write error messages for every
> existing function. There is no trivial way to automate it without adding a
> type system.
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
>
> On Sun, Jan 13, 2019 at 12:42 PM Edouard Mnd <edouard.mena...@gmail.com>
> wrote:
>
>> Oh i see so the only simple option would be to add something along the
>> line `drop(map, a) when is_atom(a)` but it would mean making the widening
>> the api surface.
>> Maybe the answer does not lie directly in elixir core but in something
>> that would run after the elixir compiler able to give suggestions about the
>> errors ? It clearly is not the scope of the discussion but I would be
>> interested to know what you think about it and what elixir api could be
>> used to make such a hint/suggestion layer.
>>
>> On Saturday, January 12, 2019 at 8:38:20 PM UTC+1, Andrea Leopardi wrote:
>>>
>>> The problem here is that Map.drop/2 expects a term as the second
>>> argument that implements the Enumerable protocol. This means that
>>> realistically we can't check for a specifically supported data type or
>>> types, since anything could implement the Enumerable protocol. For example,
>>> I might implement Enumerable for atoms and then your code would work.
>>>
>>> On Sat, 12 Jan 2019 at 19:10, Edouard Mnd <edouard...@gmail.com> wrote:
>>>
>>>>  Hi,
>>>>
>>>> I have been running into the same issue again and again with elixir
>>>> where I get a weird error like
>>>>
>>>>> (Protocol.UndefinedError) protocol Enumerable not implemented for
>>>>> "foo". This protocol is implemented for: DBConnection.PrepareStream, DBCo
>>>>> nnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream,
>>>>> Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, 
>>>>> MapSet,
>>>>> Postgr ex.Stream, Range, Stream, StreamData, Timex.Interval
>>>>>
>>>> when doing `Map.drop(foo, :sth).
>>>> Obviously i'm doing something wrong : I should give a list as a second
>>>> argument but I keep forgetting and I bet i'm not the only one.
>>>> My proposal would consist in handling this case explicitly either by
>>>> allowing for such a case to work or giving back a clear error message such
>>>> as "Are you trying to do Map.drop(foo,[:sth]) ?".
>>>> I'm greatly inspired by the rust language in asking this, indeed rust
>>>> gives you really great error messages when doing silly things.
>>>>
>>>> I hope you find my proposal clear and interesting as it clearly is not
>>>> just about Map.drop but also about giving better error messages to the
>>>> developer when doing silly things which I think is important.
>>>>
>>>> --
>>>> 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.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/elixir-lang-core/550f8801-c0d9-41ea-947a-8c3ee483c76a%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/elixir-lang-core/550f8801-c0d9-41ea-947a-8c3ee483c76a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>>
>>> Andrea Leopardi
>>> an.le...@gmail.com
>>>
>> --
>> 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/93fd3c38-c285-48b8-87d1-898fe45a1afc%40googlegroups.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/93fd3c38-c285-48b8-87d1-898fe45a1afc%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/CAGnRm4%2BUJwM4cyif%2ByBtRyge6mJ-uR%3DAiJuFkJnnazyN6-JQ-w%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BUJwM4cyif%2ByBtRyge6mJ-uR%3DAiJuFkJnnazyN6-JQ-w%40mail.gmail.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/CABu8xFDg64%3Dfy6ep74RxE%3D_cZn4oBhEN1X4Ja8j9PVga%2BMoiUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to