[erlang-questions] type specification

Kostis Sagonas <>
Sat Jul 3 09:21:31 CEST 2010


Zoltan Lajos Kis wrote:
> 
> Could you explain how the new export_type attribute relates to the 
> opaque attribute?

Declaring a type as opaque means that you want to keep the structure 
private to the defining module (which of course can manipulate the 
structure of such terms) and prevent other modules from doing operations 
to such a term that depends on its structure; dialyzer will warn you 
about such uses. Because the defining module can always manipulate the 
structure of such terms, it does not make sense to declare a type as 
opaque in some module and have it module-local (i.e., not exported).

Thus, an opaque type should always be exported.

> In R14A it seems that if I define an opaque type (without exporting it), 
> and try to use it in another module, dialyzer emits an unknown type 
> warning.

Yes, this is expected. You can not use remote types (types defined in 
some other module) that are not exported by the defining module.

> If I export the type the warning is not emitted, but the type is not 
> treated as opaque anymore...

Either I do not understand what you mean here, or I doubt this.  A small 
code example with the behavior you observe will help here (perhaps off 
list, if it is too big).

Kostis


More information about the erlang-questions mailing list