[erlang-questions] Exporting a record type

Bob Ippolito bob@REDACTED
Sun Jul 12 18:53:59 CEST 2015


On Sunday, July 12, 2015, Lloyd R. Prentice <lloyd@REDACTED> wrote:

>
> Thank you!  Your explication makes perfect sense. A basic point still
> mystifies me, however:
>
> -opaque book() :: #book{}.
>
>
> Just exactly what is going on here? My naive interpretation is that we are
> defining a function name as an alias for a record and hiding the
> composition of the record. But I'm not sure this is correct since In the
> various code examples I see the xxxx() form used in -spec definitions, but
> not code.
>

-opaque is like -type but it does not export the implementation details of
the type. This states that `book()` is a type alias for the
`#book{}` record, but it's opaque so other modules are only allowed to pass
around values of type `book()`, never create them directly. Your second
thought here is basically spot on, this is a way to define a `book()` that
can be used in `-spec` annotations.

-bob

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150712/24447ea7/attachment.htm>


More information about the erlang-questions mailing list