Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:42:15+00:00 2026-05-26T01:42:15+00:00

Say I define a type: -type yummy_foods() :: ice_cream | cake | cookies |

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:42:15+00:00Added an answer on May 26, 2026 at 1:42 am

    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:

    get_abstract_code_from_src(Filename) ->
        get_abstract_code_from_src(Filename, init_opts()).
    
    get_abstract_code_from_src(Filename, Opts) ->
        case compile:file(Filename, Opts) of
            {ok,_,Abs} -> {ok, Abs};
            Err -> Err
        end.
    
    init_opts() -> [to_pp, binary, return_errors].
    

    If you don’t have macros or you want to avoid including headers you can also get the forms using:

    epp_dodger:quick_parse_file(Filename).
    

    Original answer:

    You already have:

    -type yummy_foods() :: ice_cream | cake | cookies | spam.
    

    You can use:

    -type list_of_yummy_foods :: [yummy_foods()].
    

    This will guarantee that nothing else will be in the list though, not that all these foods will be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have a macro like this #define FOO(type,name) type name Which we could
Say I have a macro like this: #define SET_TYPE_NAME(TYPE, NAME) \ template<typename T> \
For a given type Data , I would like to define a set of
Normally, to define a grid type, I do something like this: Ext.define('MyApp.view.MyGrid', { extend:
I would like to define a type such as: type blah = AThing |
Okay, simple template question. Say I define my template class something like this: template<typename
Let's say that I have a type like this (that works): data WAE =
Say I define a variable like this: var o = new { RBI =
Let's say that I define a ClassA , that implements NSCoding protocol (this class
Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.