Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang Types Specifications

Tags:

erlang

I recently read the source code of couch-db, I find this type definition which i don't understand:

-type branch() :: {Key::term(), Value::term(), Tree::term()}.
-type path() :: {Start::pos_integer(), branch()}.
-type tree() :: [branch()].

I did read Erlang doc, But what is the meaning of Start, Key, Value and Tree? From what i understand, they are Erlang variables! I didn't find any information about this in Erlang doc.

like image 566
Chang Avatar asked Mar 11 '26 00:03

Chang


1 Answers

Start etc. are just descriptive names for the respective parts of the terms, to make it easier for humans to read the type definition. They have nothing to do with actual variable names.

(Side note: Unfortunately, even in OTP R14B, edoc still does not read -type and -spec for generating its HTML documentation - it uses the old @type and @spec instead.)

Update: The official docs on -type and -spec. More things to search for are the word success typing and the manuals for dialyzer and typer.

like image 155
ndim Avatar answered Mar 12 '26 20:03

ndim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!