librelist archives

« back to archive

optional static typing

optional static typing

From:
Роман Пельвецкий
Date:
2010-08-20 @ 21:08
Hello Mariano,
Since you are the one from a few people who wrote a language for BEAM so
competent to give an answer.
So, is it possible to add static compile time type checks for Erlang or
Efene?
Does BEAM checks types of variables only in runtime or can it be done in
compile time too?
Even if no performance boost can be achived the typecheck for function
arguments will be great.
What are your thoughts about that?

Re: [efene] optional static typing

From:
Mariano Guerra
Date:
2010-08-20 @ 21:25
2010/8/20 Роман Пельвецкий <ffindermeister@gmail.com>:
> Hello Mariano,
> Since you are the one from a few people who wrote a language for BEAM so
> competent to give an answer.
> So, is it possible to add static compile time type checks for Erlang or
> Efene?
> Does BEAM checks types of variables only in runtime or can it be done in
> compile time too?

it can be done at compile time using type[1] and spec[1] annotations
and dializer[2]

IIRC dializer was an attempt to add Hindley–Milner type inference[3]
to erlang and since it couldn't be done completely it was added as a
external tool.

> Even if no performance boost can be achived the typecheck for function
> arguments will be great.

behind the scenes erlang does some type inference to optimize the
code, see hipe[4] for more information (hipe is available in the OTP
distribution)

> What are your thoughts about that?

I think the current state is a nice balance between static and dynamic
typing, you start your small project with all dynamic types and when
it starts to get big you start to annotate the functions with types
and specs and run dializer to check for errors.

BTW efene supports type[5] and spec[6]


[1] http://www.erlang.org/eeps/eep-0008.html
[2] http://www.erlang.org/doc/man/dialyzer.html and
http://www.it.uu.se/research/group/hipe/dialyzer
[3] http://en.wikipedia.org/wiki/Type_inference
[4] http://www.it.uu.se/research/group/hipe/
[5] http://marianoguerra.com.ar/efene/docs/reference/toplevel/type.html
[6] http://marianoguerra.com.ar/efene/docs/reference/toplevel/spec.html