[erlang-questions] Types and specs [WAS: [enhancement] string:split/2]

Edwin Fine erlang-questions_efine@REDACTED
Fri Oct 10 18:47:08 CEST 2008

Question - trying to understand the spec, if I did the following:

Eshell V5.6.4  (abort with ^G)
1> string:tokens([], "abc").

Does that violate the type specification, or does it allow for the return of
an empty list?

On Fri, Oct 10, 2008 at 7:33 AM, Kostis Sagonas <kostis@REDACTED> wrote:

> Richard O'Keefe wrote:
> >
> > Can anyone explain to me why
> >
> > -spec(tokens/2 :: (string(), string()) -> [[char(),...]]).
> >
> > doesn't mention "string()" on the right hand side of the arrow?
> There is no native string() type in Erlang, as we all well know.
> So, in the language ot types, string() is just an alias for the type
> list(char()), which, for convenience, is typically written as [char()].
>  This can include both the empty string "" == [] and a non-empty list
> of characters, which is denoted [char(),...].  That's what the above
> spec signifies: the resulting list consists of non-empty strings, which
> is consistent with what string:tokens/2 actually returns.  Hope this
> explains things.
> On the other hand, I can see how this may look a bit strange to some and
> have for a long time now pondered whether a non_empty_string() type
> alias might be added to the list of built-in types.
> Kostis
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081010/eb457efe/attachment.htm>

More information about the erlang-questions mailing list