Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: how do I import a module's type declaration?

Tags:

erlang

For example, the httpc library (http://erlang.org/doc/man/httpc.html#request-4) defines some types:

status_line() = {http_version(), status_code(), reason_phrase()}
http_version() = string(), for example, "HTTP/1.1"
status_code() = integer()
reason_phrase() = string()
content_type() = string()
headers() = [header()]
header() = {field(), value()}

In my code, I want to write a function that, for example, consumes a Result and produces something else. However, rebar3 dialyzer complains:

===> Verifying dependencies...
===> Compiling xxx
===> Compiling src/httpabs.erl failed
src/httpabs.erl:35: type headers() undefined
src/httpabs.erl:35: type status_code() undefined
src/httpabs.erl:35: type status_line() undefined

So how do I import those type declarations so I can re-use them?

like image 502
Tommy Avatar asked Jan 05 '23 01:01

Tommy


1 Answers

In general, you use types exported from another module by prefixing the module name, similar to the way you use exported functions: module:type_name().

However, the types you mention are only used in the documentation; they are not actually exported from the httpc module.

You can search for -export_type directives in the Erlang/OTP source tree; I don't know any other way to know which types are actually exported.

like image 141
legoscia Avatar answered Feb 05 '23 21:02

legoscia