<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 9, 2015 at 5:05 PM,  <span dir="ltr"><<a href="mailto:lloyd@writersglen.com" target="_blank">lloyd@writersglen.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
In  Loïc's new book, The Erlanger Playbook, he advocates against using including records through *.hrl. (pp 40-41)<br>
<br>
Instead, he recommends using types:<br>
<br>
-record(state, {}).<br>
-opaque state() :: #state{}.<br></blockquote><div><br></div><div>This looks like the fairly common recommendation of: don't export records. Treat them as an opaque data type, and provide functions for working with them.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
He leaves hanging the question of how to access this record from another module.<br>
<br>
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.<br>
<br>
My case and problem is as follows:<br>
<br>
-record(book, {<br>
   ... yada yada (some seven fields)<br>
   }<br>
<br>
I define the record, then:<br>
<br>
-opaque book() :: #book{}.<br>
<br>
-export_type([book/0]).<br>
<br>
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.<br></blockquote><div><br></div><div>You don't. You have a function in the module that defines book that can create a book record, and other functions to manipulate them.</div><div><br></div><div>An example of this style would be the dict module. It uses records internally to implement a dictionary data structure, but you don't have direct access to the record(s) that it uses. Just functions to work with them.</div><div><br></div><div>-bob</div><div><br></div></div></div></div>