I don't understand why the following exercise "works" in Haskell Programming from First Principles:
type Subject = String
type Verb = String
type Object = String
data Sentence =
Sentence Subject Verb Object
deriving (Eq, Show)
s1 = Sentence "dogs" "drool"
s2 = Sentence "Julie" "loves" "dogs"
Loading this into ghci shows that it typechecks just fine, but why is it that the definition of s1
even makes sense? I'm still very new to Haskell, so at first I thought this was because in s1
Haskell was implicitly letting the Object
string be empty. But then...
*Main> s1
<interactive>:13:1:
No instance for (Show (Object -> Sentence))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show (Object -> Sentence))
In a stmt of an interactive GHCi command: print it
I'm still learning how to properly interpret these error messages, so please bear with me. But can someone explain what No instance for (Show (Object -> Sentence))
means? More specifically, how does leaving out the Object
string in s1
result in this (Object -> Sentence)
thing?
I'm sure this is stupid easy, but I don't think the book has equipped me to understand this by this point...