Theoretically Stuck

Rudolph van Graan <>
Sat Sep 2 22:30:10 CEST 2006


>>
>> How do you write code that wraps the concept/data of a
>> person? A record with name and surname fields is the obvious answer:
>>
>> -record(person,{name,surname}).
>>
>>  From now on until forever, a person is a 3-tuple.
>>
>> Now I want to make a version of person with an extra field,
>> say telephone number. Not all records have this. Some have a
>> work address as well.
>
> This seems to be leading towards wanting structs, right?
> A dynamically typed associative array.

I'd be careful before I say yes because I have no clue what a DTAA is.

In my mind a list can almost do what I want:

   Type                 Name   Surname
{[person],           ["Smith","Victor]}
{[person,with_phone],["Smith", "Victor","+332211123123"]}

Both would match this pattern

{[person|_],[Name,Surname|_]}

and only the second one would match

{[person,with_phone|_],[Name,Surname|_]}

so we have a person-with-a-phone "inheriting" from person

Maybe wrap it in a tuple so that we know this is a  
special,"inherited" type:

{dynamic_record,{[person,with_phone|_],[Name,Surname|_]}}

My biggest concern here is that you lose the implicit efficiency of  
tuples, but I haven't measured how slow it is yet and we've lost  
record syntax. 



More information about the erlang-questions mailing list