specifications - Erlang: Is there a way to "inherit" in a -spec? -


is there way "inherit" specifications in -spec in erlang?

let me give example:

i'm writing typical convenience function like:

start_link(opts) -> gen_server:start_link(?module, [opts], []). 

i want write -spec like:

-spec start_link(opts) -> result when     opts :: [opt],     opts :: {timeout, pos_integer()}           | {return_type, returntype},     returntype :: binary | string, 

the result of gen_server:start_link/3 is

result = {ok,pid} | ignore | {error,error} pid = pid() error = {already_started,pid} | term() 

i have copy or use template start_link functions. inherit result of gen_server:start_link/3 somehow.

is there way this? thoughts on this?

thanks everybody!

you write type definition like:

-type start_link_ret() :: {ok,pid()} | ignore | {error,{already_started,pid()} | term()} 

(you can't use when in -type definitions, needs go same expression.)

and write spec like:

-spec start_link(opts) -> start_link_ret() when     opts :: [opt],     opts :: {timeout, pos_integer()}           | {return_type, returntype},     returntype :: binary | string. 

if you're going use start_link_ret() in several modules, can export it:

-export_type([start_link_ret/0]). 

and use foo:start_link_ret() in other modules.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -