Question:
I would like to generate a HTML form from types in Haskell.
Color = Green | Yellow | Red | ....
Fruit = Apple Color Int
| Banana Color Int String
| ....
User shall pick a dropdown list with option of ("Apple","Banana") or ("Green","Yellow","Red")
Question:
But how to get ALL values of type Fruit/Color values to HTML ? something like:
[ toHtml v <- Fruit.values() ]
-- render "Apple" to html
-- render "Banana" to html
expected:
<dropdown> : values :apple/banana...
<dropdown> : values of green/yellow...
<input text> : for Int
<input text> : for String(if Banana was selected
The
Dataclass helps here, e.gTo get
Fruitwhere data constructors also have fields you'd have to work harder but the required info should be available within theDataTypedata type.