Question

See my attempt at a record definition below. The Erlang compiler doesn't consider the key field definition as valid syntax.

Is there a way to accomplish something similar, without making key a record or just a undefined tuple structure like key :: tuple()?

-record(spot, { 
      key :: {id :: integer(), version:: integer(), live :: boolean()},
      name :: binary(), 
      short_description :: binary(), 
      address1 :: binary(), 
      address2 :: binary(),
      address3 :: binary(),
      postalcode :: binary(),
      city :: binary(),
      phone :: binary(),
      website_url :: binary(),
      menu_url :: binary(),
      last_modified_at :: erlang:timestamp()}).
Was it helpful?

Solution

{id :: integer(), version:: integer(), live :: boolean()} is not valid type specification. You can use record definition or you have to specify only type information which is {integer(), integer(), boolean()}.

So using record would look like.

-record(spot_key, {
         id :: integer(),
         version:: integer(),
         live :: boolean()
     }).

-record(spot, { 
      key :: #spot_key{},
      name :: binary(), 
      short_description :: binary(), 
      address1 :: binary(), 
      address2 :: binary(),
      address3 :: binary(),
      postalcode :: binary(),
      city :: binary(),
      phone :: binary(),
      website_url :: binary(),
      menu_url :: binary(),
      last_modified_at :: erlang:timestamp()
    }).

OTHER TIPS

If you dont want to create record for key, you cannot use field names in the key tuple. If you remove that field names , I believe compiler will be able to eat it.

I mean try instead of

   -record(spot, { 
      key :: {id :: integer(), version:: integer(), live :: boolean()},
      name :: binary(), 

write

   -record(spot, { 
      key :: {integer(), integer(), boolean()},
      name :: binary(), 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top