[erlang-questions] Exporting a record type

Fri Jul 10 02:05:08 CEST 2015

Hi folks,

I've asked Loïc Hoguin directly about this, but I thought an elaboration and discussion might be of interest to many on this list.

In  Loïc's new book, The Erlanger Playbook, he advocates against using including records through *.hrl. (pp 40-41)

Instead, he recommends using types:

-record(state, {}).
-opaque state() :: #state{}.

He leaves hanging the question of how to access this record from another module. 

The Erlang Types and Function Specifications doc suggests that the type can be exported using -export_type(...). But, to my feeble mind, the exposition is less than clear.

My case and problem is as follows: 

-record(book, {
   ... yada yada (some seven fields)

I define the record, then:

-opaque book() :: #book{}.


Now, I access a remote db in a different module and want to instantiate a book record, but it's not at all clear to me how to do so.

If I do the following in the console...

wg_books:book(). I get:

** exception error: undefined function wg_dets_books:book/0

This seems to be an all-to-little documented corner of Erlang. Is there a kind soul who can help show the way?

Many thanks,



More information about the erlang-questions mailing list