Suppose we need to store a custom data object into a database and be able to read it back.
data Country = USA | MEXICO
instance Show Country where
show USA = "United States"
show MEXICO = "Mexico"
Suppose after quering a database, we get a string “Mexico”. How to parse it into a Country datatype?
For example, for an integer, I would do the following:
read “2” :: Int