Search code examples
compiler-constructionerlangtype-systems

Erlang type system


I've been scrounging around the web looking for various typing practices of Erlang programs and there seem to be a few... although its somewhat difficult to find a solid source of info namely Im looking for practical info about:

1.-specs - this one looks pretty attractive. a few places mention that the functions that have an associated -specs directive with it are checked at compile time(for correct type usage)... I cant seem to find more info on how to use it (which tool to use - Dialyzer,TypEr?). Im really eager to create a small parser/code-gen that would generate these "specs" from function declarations of the form

functionName(param1 :List, param2 :Tuple) -> ...

I have not seen if -spec supports abstract types (user declared types - "Car" type -

{car,{weight,_},{height,_},{maxSpeed,_}}

2.-deftype directive mentioned here

Erlang would become so much more powerful for me, if I could start typing things and have them be checked at compile time. The run-time the parser/code-gen I mentioned above would generate guard type checks in the output source-code.


Solution

  • More info on the type and spec attributes here:

    http://www.erlang.org/eeps/eep-0008.html

    Dialyzer can be used to check them (see dialyzer --help).

    Typer can be used to generate them (see typer --help).