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

Richard O'Keefe ok@REDACTED
Tue Oct 14 03:42:57 CEST 2008

On 13 Oct 2008, at 7:49 pm, Kostis Sagonas wrote:

> Richard O'Keefe wrote:
>> On 11 Oct 2008, at 12:33 am, Kostis Sagonas wrote that
>> [[char(),...]] means list of non-empty strings, which
>> is more precise than [string()].
>> Would [char()|string()] also work?
> No.  This is a different type, which does not express what you want  
> here.
> Note that in the language of types | does not mean list tail, but  
> instead means type union.  The above type denotes a (possibly empty)  
> list consisting of characters or strings.

Then we have a rather nasty syntax problem here.

If I had written [(char() | string()] where the bar is NOT
part of the list syntax, I would certainly expect that to
mean a list of things each of which is a char or a string.
But with the vertical bar being part of the list syntax,
I would expect [H | T] as a type to mean the type of cons
cells whose heads are of type H and whose tails are of type T.
If it *doesn't* mean that, it should be a syntax error.

More information about the erlang-questions mailing list