Haskell 数据构造函数是否支持currying?
Haskell中的所有功能都类似于:Haskell 数据构造函数是否支持currying?,haskell,Haskell,Haskell中的所有功能都类似于: Prelude> type Subject = String Prelude> type Verb = String Prelude> type Object = String Prelude> data Sentence = Sentence Subject Verb Object deriving (Eq, Show) Prelude> :t Sentence Sentence :: Subject -> Verb
Prelude> type Subject = String
Prelude> type Verb = String
Prelude> type Object = String
Prelude> data Sentence = Sentence Subject Verb Object deriving (Eq, Show)
Prelude> :t Sentence
Sentence :: Subject -> Verb -> Object -> Sentence
句子是一个数据类型,但为什么它显示为一个函数?
即使我用一个值替换,它也感觉像一个函数
s1 = Sentence "dogs" "drool"
数据类型也支持咖喱吗
v this is name of a new type
data Sentence = Sentence Subject Verb Object
^ and this is a function called "value constructor"
(it may or may not have same name with the new type)
所以答案是肯定的,Curry也适用于“值构造函数”函数。正如Jokester所指出的,令人困惑的是,这里有两个东西都被命名为“
句子”
”:
类型,以及句子
数据构造函数语句
语句
类型的对象不是函数。它们只是普通值:
:t (Sentence "he" "likes" "cake")
:: Sentence
如果您尝试过
:ts1
,您会看到它的类型是对象->句子。