peculiar type spec

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

peculiar type spec

Raghav Karol
I recently came across this type specification 

-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.

* Is this a `type variable', see [1] and how does one interpret it? 

Best,
Raghav


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: peculiar type spec

Richard Carlsson-3
If you refer to that whole line you quoted, then no, that's a "type declaration". "Index" and "SecondaryKey" are just names that act as placeholders, and since there is no other type information along with them, those fields could have any type.

A "type variable" is a variable used as a parameter of the declared type, as in this example (see section 7.3 in the link you included):

-type orddict(Key, Val) :: [{Key, Val}].

Here, Key and Val are both type variables. You could for exampe use this to define another type, like so:

-type my_dict() :: orddict(atom(), integer()).


        /Richard

2017-01-24 23:02 GMT+01:00 Raghav Karol <[hidden email]>:
I recently came across this type specification 

-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.

* Is this a `type variable', see [1] and how does one interpret it? 

Best,
Raghav


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions