[erlang-questions] NIF resource and typespecs
Fri Apr 11 12:25:03 CEST 2014
On Thu, Apr 10, 2014 at 12:11 PM, Sverker Eriksson wrote:
> On 04/09/2014 03:25 PM, Loïc Hoguin wrote:
> > Hello,
> > NIF resources appear as a magic empty binary on the Erlang side.
> > What typespec should I use for them though? Is there anything
> > better than this?
> > -opaque my_nif_resource() :: any().
> > Thanks.
> I think this is the way to go:
> -type my_nif_resource() :: any().
> @Tuncer: Wasn't that your conclusion?
Yes, I settled on that because:
1. If you declare :: any() as an opaque type, then the compiler will
complain that it's underspecified.
2. Opaque types only make sense when exported, and the compiler will
rightly complain about that.
Also, the magic empty binary is an implementation detail and may
change in any erts release, so should not be pattern matched at all.
More information about the erlang-questions