Say I define a type:
-type yummy_foods() :: ice_cream | cake | cookies | spam.
This seems like a great way to do what I would do with an enumeration in C. I can have Erlang check things for me with Dialyzer. But say I want to generate a list of all the yummy foods and do something with it. How would I get this:
[ice_cream, cake, cookies, spam]
I don’t care about ordering, just that everything’s there. Alternatively, am I missing some common Erlang idiom that would make this whole approach seem stupid?
Ah, my original answer is probably irrelevant…
To do what you are describing, you have to retrieve the type definition from the list of forms in the file, parse it or have someone parse it for you and if it is indeed a union type, retrieve the elements and return them in a list.
If you want to do it from source, you will need something like:
If you don’t have macros or you want to avoid including headers you can also get the forms using:
Original answer:
You already have:
You can use:
This will guarantee that nothing else will be in the list though, not that all these foods will be.