Missing features in Erlang type system and several additional question related to it
Tue Aug 31 11:07:03 CEST 2010
I'm working with json using mochiwebjson2 library and need to
specialize next type:
-type packet_encoding() :: 1 | 0.
-type packet() :: [integer(), packet_encoding(), binary()].
But it's turned out, Erlang doesn't have support for lists with fixed
data amount and type packet doesn't compiling. If you wondered why I
choose list over tuple, it's because in json there is no tuple and i
serialize packets from erlang to json via mochiwebjson2, which also
doesn't work with tuples.
But in any case i guess this is missed feature of Erlang type system
and it should be addressed.
Another issue is with parametrized erlang modules. I use mochiweb
which uses this feature. And for things like Req:method(), Dialyzer
thinks that Req is atom. Maybe it even doesn't know about parametrized
modules. Maybe, there is some type or additional hint for such cases?
I also have issue with Dialyzer and dirty check on dict'ness of value.
Maybe there is a point to add some 'true' is_dict guard? because dirty
is_record(Term, dict, 8) also made it complain when i lately use some
functions from dict module.
Looking for examples of type declaration i investigated Erlang sources
and found two unknown directives: -opaque and -file. Can someone
explain, what are they for?
I've also heard some mention about runtime type checking, which can be
addition to Dialyzer static checking. But have no luck to find out how
to enable it. Maybe someone can point me out which tool is responsible
for this functionality?
About char() type. In documentation it's described as: char()
0..16#10ffff. Maybe this is some typo? Or what is mean? Here
http://schemecookbook.org/Erlang/StringBasics chars described as 4-
More information about the erlang-questions