I have the following type:
data Color = Red
| Yellow
| Green
| ...
I want a function mapping string representation to specific Color.
str2Color :: String -> Color
str2Color "Red": Red
str2Color "Yellow": Yellow
str2Color "Green": Green
I could enumerate all strings, but problem is the list of all colors is very long. Is there any simpler way?
ps: Let's assume all input strings have a corresponding Color, for ease of exposition.
deriving Readfrom theColortype, then you can useread :: String -> Colorto convert a string to the correspondingColor.