[erlang-questions] records and types

Torben Hoffmann torben.lehoff@REDACTED
Mon Oct 17 09:06:25 CEST 2011


I am afraid you need to create a record for every field type.

Then you can write something like:
-type field() :: #text_field{} | #integer_filed{}.
-record(schema, {fields :: [field()]}).

And then you might want to look at Ulf Wiger's exprecs library - it may 
help with this kind of repetitive code.

Cheers,
Torben

On Mon Oct 17 08:59:08 2011, Ward Bekker wrote:
> I have the following (compiling) record and type definitions:
>
> -record( field, {name :: unicode:unicode_binary()}).
> -record( schema,{name :: unicode:unicode_binary(), fields :: [ #field{} ]}).
> -type text_field() :: #field{}.
> -type integer_field() :: #field{}.
>
> The following function will give compile errors:
>
> demo_schema() ->
>      #schema{ name = u("stackoverflow_post"),
> 	     fields = [
> 		       #text_field{ name = u("title") },
> 		       #integer_field{ name = u("user_id") }		
> 		      ]
> 	   }.
>
> Is it possible to create a field record using the type definition name? Or do I need to define a record for every field type?
>
> Regards,
>
> Ward
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list