【发布时间】:2015-05-10 20:21:23
【问题描述】:
使用此代码:
-- Store a person's name, age, and favourite Thing.
data Person = Person String Int Thing
deriving Show
brent :: Person
brent = Person "Brent" 31 SealingWax
stan :: Person
stan = Person "Stan" 94 Cabbage
getAge :: Person -> Int
getAge (Person _ a _) = a
访问 stan 使用的年龄:
getAge stan
打印: 94
定义stan不需要括号。
但是getAge Person "a" 1 Cabbage 导致错误:
<interactive>:60:8:
Couldn't match expected type `Person'
with actual type `String -> Int -> Thing -> Person'
Probable cause: `Person' is applied to too few arguments
In the first argument of `getAge', namely `Person'
In the expression: getAge Person "a" 1 Cabbage
我需要使用括号:
*Main> getAge (Person "a" 1 Cabbage)
1
为什么在这种情况下需要括号?但是在定义stan = Person "Stan" 94 Cabbage时不需要括号?
【问题讨论】: