[erlang-questions] Overloaded function specifications as types

Dániel Szoboszlay dszoboszlay@REDACTED
Mon Jan 23 12:32:05 CET 2017


>
> > -spec bar(fun((integer()) -> integer()) | fun((atom()) -> atom())) -> ok.
> > %% Allows fun erlang:atom_to_list/1, which doesn't work on integers at
> all.
>
> I'm seriously confused as I do not see anything related to lists here...
>
> Can you elaborate?
>
>
I'm sorry, editing mistake! atom_to_list is of course not a good example.
(I started off with different code samples and edited them a couple of
times.)

The correct example would be a function that only takes atoms and returns
atoms. E.g.

good_example(ok) -> ok;
good_example(Other) when is_atom(Other) -> error.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170123/16850607/attachment.htm>


More information about the erlang-questions mailing list