New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to define and enumerate union types. #943

Closed
congwenma opened this Issue Feb 13, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@congwenma

congwenma commented Feb 13, 2018

I find myself defining union types, and when trying to use them I have to explicitly use their names instead of just enumerate through them,

It seems that by having union type automatically classifying types(which is wonderful), we lost a use case of dynamically expand its content into possible test cases. Would it be too unstable to have this bit of dynamic-ality in elm?

In any case, I'm wondering how the following test case is possible in elm.

const alphabet = "abcdefghijklmnopqrstuvwxyz".split('') 
// Here's what I'd imagine would be UnionType in elm ->
//     type Alphabet = A | B | C | D | E.....
const germanAlphabet = "abcdefghijklmnopqrstuvwxyzäöüß".split('')

const expand = n => [...Array(n)]

const testSetup = (unionType) => {
  const randomTestString = expand(1000) 
    .reduce((accu) => {
       const alphabetIndex = Math.floor(Math.random() * unionType.length);
       return accu + unionType[alphabetIndex]; 
       // ^^ Can you do something like this in Elm?
    }, "");
  return randomTestString
}

const randomText = testSetup(alphabet)
const randomGermanText = testSetup(germanAlphabet)

And lets pretend that in this fictional universe, people are very proud of a letter they are assigned to, so much so that they would gladly label themselves in this fashion of elm:

type alias Person = { 
  name: String,
  letter: AlphaBet
}
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Feb 13, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Feb 13, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz evancz added the request label Mar 7, 2018

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Mar 7, 2018

Member

This seems like a language feature request, but I do not get it at all. We do not have any short-term plans to make changes to type declarations though, so I will close.

Member

evancz commented Mar 7, 2018

This seems like a language feature request, but I do not get it at all. We do not have any short-term plans to make changes to type declarations though, so I will close.

@evancz evancz closed this Mar 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment