As many of you probably know I have been working to add types to LFE. Or rather to add type declarations and function specifications in an Erlang compatible way. I just want to report what is happening and how far I have gotten with the work.
So far:
- Defined a syntax which is very close to the erlang syntax, mainly the left parentheses have been moved to make a more lisp-like syntax. As far as I know everything you can write in the erlang works in LFE.
- Defined macros deftype, defopaque and defspec (with corresponding forms define-type, define-opaque-type and define-function-spec) for defining types and specs.
- You can add types to module metadata where it is checked and used as well as using the macros.
- You can add (spec ...) to defun (like with (doc ...)) and define-function metadata where it is accepted but as yet ignored.
- Including erlang .hrl files with type defs and function specs works.
- The type defs and function specs end up in the right place with the right syntax in the core erlang files so dialyzer should be able to handle them when I get around to cleaning up and releasing ldiayzer.
- Being able to have include files, both .lfe and .hrl, with type defs and func specs are why we need the define-XXX forms, though we could do without the type forms.
So what needs to be done now is:
- Extend the syntax so it can handle everything the erlang version can.
- Improve the lint to check the types/specs better.
- And, of course, fix ldialyzer so it will have some practical use.
Everything so far is in the 'dev-types' branch and is accessible. If you have pulled this branc before then delete it and do it again as I tend to use it as a store and have force pushed somethings. There is even a very basic doc file lfe_types which says a bit and gives some examples. Only some types are documented but this is mainly for showing how to do it, all the existing predefined erlang types shoudl work. To give some more help I include 2 pairs of files, a .hrl file with erlang syntax and a .lfe with the LFE equivalent: include_types for type defs, and include_specs for func specs.
Have fun,
Robert