Currently I’m studying type parameters. In the book Learn You a Haskell For Great Good the author gives an example in section Type Parameters :
data Maybe a = Nothing | Just a
When I try to implement this Maybe a
, I have to add deriving (Show)
, otherwise when I call Just "Hey"
, Haskell warns we that "No instance for Show (Maybe String)
.
I’m curious why there’s no deriving (Show)
in author’s example. In previous sections, the author emphasized the need of deriving (Show)
when we want to define a new type and show it in the prompt. Maybe since String
is of typeclass Show
so we don’t need to add deriving (Show)
? I feel confused!