I have run into a problematic use case a couple of times, and based on Slack discussions earlier today, it seems I'm not alone.
The situation occurs when, for some reason, I need to maintain a list of all constructors of a union type. The example given in Slack by mltsy: type State = Alabama | Alaska | Arizona | Arkansas | ... allStates = [ Alabama, Alaska, Arizona, Arkansas, ...] stateSelectBox : List State -> Html Msg stateSelectBox states = let stateValues = List.map toString states in ... In the example above, simply turning allStates into a list of strings would be fine for this particular use case, but in the context of a larger system, it could be inadequate–other functions besides stateSelectBox may want to utilize the power of performing a case over the union type. However, the above solution is also structurally undesirable–if a new type is added to State, then the programmer must also remember to update allStates separately. The duplication and tight coupling are disconcerting, and yet I can't see a viable alternative that preserves the power of types without incurring the duplication. I have wondered if a language-level construct that takes a union type and returns a list of all constructors for that type would be appropriate for Elm. Just a thought. - Matt -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
