【发布时间】:2015-12-13 04:07:18
【问题描述】:
所以我想从类型同义词列表中返回一个值。
type Skill = (String,Int)
type Stat = (String,Int)
data Player = Player {
hitpoints :: Int,
experience :: Int,
stats :: [Stat],
skills :: [Skill],
pos :: Point
}
我想在
中返回stat"Toughness"的值
Player 10 0 [ ("Strength", 5), ("Toughness", 1) ] [ ("Fisticuffs", 1) ] (1,1)
到现在为止
instance Combatant Player where
defense (Player _ _ ([(s,a)]) _ _) = (List.find (s=="Toughness") ([(s,a)]))
但它返回以下错误
Couldn't match expected type `Int'
with actual type `Maybe (GHC.Base.String, Int)'
In the expression: (find (s == "Toughness") ([(s, a)]))
In an equation for `defense':
defense (Player _ _ ([(s, a)]) _ _)
= (find (s == "Toughness") ([(s, a)]))
Couldn't match expected type `(GHC.Base.String, Int)
-> ghc-prim-0.4.0.0:GHC.Types.Bool'
with actual type `ghc-prim-0.4.0.0:GHC.Types.Bool'
In the first argument of `find', namely `(s == "Toughness")'
In the expression: (find (s == "Toughness") ([(s, a)]))
In an equation for `defense':
defense (Player _ _ ([(s, a)]) _ _)
= (find (s == "Toughness") ([(s, a)]))
我还是 Haskell 的新手,我不知道我应该做什么。我查看了不同的来源并关闭了我所看到的关联列表?
【问题讨论】:
标签: haskell type-synonyms