Search code examples
erlangejabberdmnesia

ejabberd - mnesia table record definition : " ::binary() "


I'm trying to understand the meaning and purpose of ::binary() that exist in record definition but don't really understand it. Appreciate if anyone can help me to understand this.

Example : mod_offline.hrl


Solution

  • This is a type declaration. This is described in the "Type Information in Record Declarations" section.

    The meaning is that the value of that record field is supposed to be a binary. Since Erlang is a weakly typed language, the compiler doesn't care about this, but there is a static type checker called Dialyzer, that tries to find places in the code that puts something other than a binary in that field, or expects the field to hold something other than a binary.

    For a gentle introduction to type specs and Dialyzer, see the Type Specifications and Erlang chapter of Learn You Some Erlang.