我不明白,为什么下面的练习“作品”,在从第一原理哈斯克尔编程:数据构造的部分应用程序
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"
加载到这个ghci中表明,它typechecks就好了,偏偏是那s1
的定义更有意义?我对Haskell仍然很陌生,所以起初我认为这是因为在s1
Haskell隐含地让Object
字符串变空。但然后...
*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
我还在学习如何正确解释这些错误信息,所以请耐心等待。但有人可以解释什么No instance for (Show (Object -> Sentence))
的含义?更具体地说,如何在s1
中忽略Object
字符串导致这个(Object -> Sentence)
的事?
我敢肯定,这是愚蠢的容易,但我不认为这本书已经具备了我这个角度来理解这个...
查找功能柯里并牢记像Sentence这样的数据构造函数与普通函数非常相似。 – Alec