Static type checking in erlang

I slowly fall in love with Erlang and have only one big, big problem.

I am a big fan of languages ​​like Standart ML and ocaml with their strong static type checking.

Is there a good and clean way to introduce somesort of static typechecking in erlang. I look at the -type and -spec .

Does anyone have a good solution?

+7
source share
4 answers

I was there! I love both OCaml and Erlang and use them regularly.

By the time I started using Erlang, I had many years of experience with OCaml. It took me several weeks to adapt to the fact that there is no static typechecker in the compiler. But after that the pain completely disappeared.

To some extent, working without typechecker is a useful exercise. It was an educational experience for me and really made me a better programmer.

There is, however, an external static typechecker for Erlang called Dializer . This is very useful to me. The problem is that you need to call it separately and it is slow. Running it once in a while (for example, before the code or automatic assembly of parts) works fine. I never tried to run it after each compilation, as that would be too much of a distraction to wait for completion.

+12
source

check dialyzer tool

Dialyzer is a static analysis tool that identifies software inconsistencies, such as certain type errors , code that has become dead or inaccessible due to some programming error, unnecessary tests, etc. in separate Erlang modules or entire (sets) of applications.

+3
source

For many years there have been attempts to create type systems at the top of Erlang. One such attempt occurred back in 1997 by Simon Marlow, one of the leading developers of the Glasgow Haskell Compiler and Philip Wadler, who worked on the Haskell design and contributed to the theory behind monads (read the article on this type of system). Joe Armstrong later commented on the article:

One day Phil called me and announced that a) Erlang needs a type system, b) he wrote a small prototype of the type system and c) he had one summer vacation and was going to write a type system for Erlang and "were we interested?" The answer is yes.

Phil Wadler and Simon Marlo worked on a type system for over a year, and the results were published in [20]. The project results were somewhat disappointing. Firstly, only a subset of the language with the possibility of type checking, the main omission is the lack of process types and messages of interprocess type control.

http://learnyousomeerlang.com/types-or-lack-thereof

+3
source

I mainly use -spec and -type for documentation purposes: you write spec with -spec , then test it with TypEr and then (after adding extra information to edoc format) generate documentation

+2
source

All Articles