[erlang-questions] custom type specifier

Davide Marquês <>
Wed May 13 14:20:01 CEST 2009


Hi there!

Where can I find some indications on how to define a type specifier so in my
> module I can have some new types like:
>
> <<Value:Size/huffman,..>>
> or
> <<Value:Size/fibonacci,..>>
> or
> <<Value:Size/base64,...>>
> or any custom encoding method for that matter.
>
> My question may seem (and probably is) pretty trivial, but I am new in
> writting code with erlang and some things are not pretty easy to find if you
> do not know where to look.
> I have looked into unicode.erl (in R13B source code) but haven't seen
> anything relevant to answer my question.
>

I'll assume your don't really want to extend the language/compiler to
support those new type specifiers and only want them *in your modules*. :)
With that in mind, parse_transform looks like the tool for the job!
Using it you could specify those new fancy types and have them turned into
the [existing] 'binary' type on compilation
(more experience folks, what do ya think?).

To figure out how parse_transform works follow the first posts from this
blog: http://chlorophil.blogspot.com/
By the way:

> Programmers are strongly advised not to engage in parse transformations and
> no support is offered for problems encountered.
>
http://www.erlang.org/doc/man/erl_id_trans.html

:Davide
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090513/eb7764da/attachment.html>


More information about the erlang-questions mailing list