Teach you Haskell discusses the following data type:
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
deriving (Eq, Ord, Show, Read, Bounded, Enum)
The book shows how to use readto parse strings into types Day.
$ read "Saturday" :: Day
Saturday
However, I can pass a value other than the day, resulting in an exception.
$ read "foo" :: Day
*** Exception: Prelude.read: no parse
What is the safe type of use readin the example above?
source
share