[erlang-questions] dialyzer and #record vs tuple

Szoboszlay Dániel <>
Fri Jun 7 20:46:41 CEST 2013


Hi,

You may also try to remove the type declaration from the record but  
declare a new type that specializes your now generic record type, like  
this:

-record(foo, {bar = 0}).
-type foo() :: #foo{bar :: integer()}.

-spec new_foo(Id :: integer()) -> foo().

You will have to write some -spec lines, but personally I'd do that  
anyway...

Daniel

On Fri, 07 Jun 2013 10:23:01 +0100, Vincent de Phily  
<> wrote:

> On Friday 07 June 2013 12:08:18 Kostis Sagonas wrote:
>> There is no perfect `solution' to this .
>>
>> Dialyzer works at a level where records have been expanded into tuples
>> and thus records and tuples are indistinguishable between them.
>> Furthermore, it makes the assumption that within a module any tuple with
>> a record tag and with a size that matches some typed record declaration
>> refers to the declared types. So you have two options:
>>
>>   1. Use different tags for records and tuples e.g. foo_rec vs. foo (as
>> you write)
>>
>>   2. Do not declare types for records that for some reason or another
>> you also want to have similar looking tuples (as you write, declaring
>> the "union" of the types does not make much sense).
>>
>>  From the two options, I personally very much prefer the first.
>
> Thanks for confirming this, pity there's no nice way of handling that  
> problem
> but I'll stick with option 1 for now.
>
> Maybe when frames arrive in erlang it'll fix that issue :)


More information about the erlang-questions mailing list