[erlang-questions] Exporting a record type

lloyd@REDACTED lloyd@REDACTED
Sun Jul 12 20:57:36 CEST 2015


Thank you, Bob.

Can't say how much I appreciate the support of this great community. One day, perhaps, enough will seep through my skull to contribute back.

Best wishes to all,

Lloyd

-----Original Message-----
From: "Bob Ippolito" <bob@REDACTED>
Sent: Sunday, July 12, 2015 12:53pm
To: "Lloyd R. Prentice" <lloyd@REDACTED>
Cc: "Jesper Louis Andersen" <jesper.louis.andersen@REDACTED>, "erlang-questions" <erlang-questions@REDACTED>
Subject: Re: [erlang-questions] Exporting a record type

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

>





More information about the erlang-questions mailing list