[erlang-questions] Why use -record() ?

Krzysztof Jurewicz krzysztof.jurewicz@REDACTED
Sat Jun 8 12:26:31 CEST 2019


> There are few other benefits of records over other data types: type testing and pattern matching. These subject has been widely covered at [official documentation](http://erlang.org/doc/programming_examples/records.html):
>
> ```erlang
> %%
> %% type testing
> myfun(X) when is_record(X, person) -> ...

It is however worth to mention that “type testing” of records doesn’t actually perform type testing of record fields. is_record(X, person) checks only that X is a tuple of correct size and that its first element is 'person'. Therefore is_record(#person{name=foo}, person) will return true despite the name field being type annotated as binary. Dialyzer too wil not always catch type errors in record construction.



More information about the erlang-questions mailing list