[erlang-questions] soft/optional typing

Matthew O'Gorman mogorman@REDACTED
Wed Jun 13 16:24:09 CEST 2007


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

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?

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