[erlang-questions] soft/optional typing

Tobias Lindahl tobias.lindahl@REDACTED
Wed Jun 13 16:42:29 CEST 2007


Matthew O'Gorman wrote:
> personally I think the proposed syntax someone brought up earlier
> foo( Var::integer(), Var2::atom()) ->

This is a bit orthogonal to our work. The suggested syntax was for guard 
expressions, while we are working on a documentation/analysis angle that 
(at least for now) would have no semantic meaning in the actual 
language. As that we would like to have the contracts clearly separated 
from the code of the function.

Of course, our syntax for the contracts is pretty similar to the 
suggested type guard syntax, which is probably a Good Thing(TM).

> 
> would be better or even
> foo( Var::integer, Var2::atom) ->
> 
> is :: used for anything currently by the parser?  As for the returns
> something like
> foo( Var::integer, Var2::atom) ->
> (Var * 2)::integer.
> or
> Var::integer.
> if parens are not needed.  what do you think?

In our type domain we have single-point types for atoms and integers. 
This means that the type "integer" means "the atom: integer" while 
"integer()" means "an undefined integer".

Best,
Tobias


> 
> Mog
> On 6/13/07, Tobias Lindahl <tobias.lindahl@REDACTED> wrote:
> 
>> jm wrote:
>> > This sounds promising. Not having read the papers yet; Do you know what
>> > the syntax will be? Can you give a simple example?
>>
>> The basic type syntax is an extended version of the syntax in the paper
>> on typer and it is also similar to the edoc syntax. You give your
>> contracts on a per-function basis as a compiler attribute.
>>
>> -spec(foo/2 :: ((integer(), atom()) -> integer())).
>>
>> You can also specify the variable names of your function to simplify
>> additional comments
>>
>> -spec(foo/2 :: ((X :: integer(), Y :: atom()) -> integer()).
>>
>> Also, you can use type variables in the type position.
>>
>> -spec(bar/1 :: ((X :: Alpha) -> Alpha)).
>>
>> You can put bounds on your type variables.
>>
>> -spec(bar/1 :: ((X :: Alpha) -> Alpha) when is_subtype(Alpha,number())).
>>
>> Also, to capture something similar to intersection types, you can give
>> more than one contract
>>
>> -spec(baz/1 :: ((integer() | atom()) -> integer());
>>                 (([byte()]) -> atom)).
>>
>> We also plan to have type aliases to keep the verbosity down a bit
>>
>> -type(int_or_atom() :: (integer() | atom())).
>>
>> Also, the contracts can involve typed records
>>
>> -record(foo, {bar::integer(), baz}).
>>
>> which then are used as
>>
>> -spec(gazonk/1 :: ((#foo{}) -> integer())).
>>
>>
>> This is the syntax we are currently using, but it is not set in stone.
>> Comments are welcome.
>>
>> Tobias
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>



More information about the erlang-questions mailing list