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 ...
--
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 elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The problem is, this would only work when all the constructors had 0 arguments , or arguments of the same type. Otherwise, what would the type of such a list be?
Building on Charles, how would this handle recursive union types?
Adding this to the language feels like how other languages evolve, which is haphazardly.I rather see a more general solution to this problem via some type of constraint-based type. For example, imagine you can define something as String but with a constraint that limits the values they can contain. This would solve all current problems we have with using types as Enums. We'd have exhaustive case statements checking and since it's already a String converting to String is unnecessary.
## The following is the only line that lists the state names!define(`stateList', ``Alabama', `Alaska', `Arizona', `Arkansas'')dnl
type AState = m4AltSep(stateList)
allAStates = m4ListStates(stateList)
allAStateNames = m4ListStrings(stateList)
## The following is the only line that lists the state names!
type AState = Alabama | Alaska | Arizona | Arkansas
allAStates = [ Alabama, Alaska, Arizona, Arkansas ]
allAStateNames = [ "Alabama", "Alaska", "Arizona", "Arkansas" ]
define(`m4foreach',`ifelse(eval($#>2),1,`pushdef(`last_$1',eval($#==3))dnl`'pushdef(`$1',`$3')$2`'popdef(`$1')dnl`'popdef(`last_$1')dnl`'ifelse(eval($#>3),1,`$0(`$1',`$2',shift(shift(shift($@))))')')')dnldefine(`m4AltSep', `m4foreach(`xstate', `xstate`'ifelse(last_xstate,0,` | ')',$@)')dnldefine(`m4ListStates', `[ m4foreach(`xstate', `xstate`'ifelse(last_xstate,0,`, ')',$@) ]')dnldefine(`m4ListStrings', `[ m4foreach(`xstate', `"xstate"`'ifelse(last_xstate,0,`, ')',$@) ]')dnl
cat elmdefs.m4 YourFile.elm.m4 | m4 > YourFile.elm
type alias UsState =
{ name : String
, code : String
, licenseFormat : String
}
states
|> List.filter (\state -> state.code == "AL")
|> List.head