[英]Couldn't match type `[Char]' with `Char' for spa
I am trying to give the names of spa a given supervisor that rated the skill service along with their rating result for each spa.我正在尝试将水疗中心的名称提供给对技能服务进行评分的给定主管以及他们对每个水疗中心的评分结果。 But I keep getting this error shown below.
但我不断收到如下所示的错误。 Sorry if my code look horrible since I am new to Haskell.
对不起,如果我的代码看起来很糟糕,因为我是 Haskell 的新手。
* Couldn't match type `[Char]' with `Char'
Expected type: Spa -> Service
Actual type: Spa -> [Service]
* In the second argument of `(.)', namely `getService'
In the first argument of `filter', namely `((== se) . getService)'
In the expression: filter ((== se) . getService)
I tried by retrieving and filtering for the supervisor.我尝试为主管检索和过滤。 Then I output it all.
然后我 output 这一切。 Is it possible to just output name of supervisor, spa and level rating?
是否可以仅 output 主管名称、水疗中心和等级等级? Am I going the right track?
我走对路了吗? How to fix the error?
如何修复错误?
data Spa = Spa SID Brand Area Stars [(Service, LevelRating)]
-- spa service
getService :: Spa -> [Service]
getService (Spa _ _ _ _ xs) = map fst xs
-- filter spa service
spaService :: Service -> [Spa] -> [Spa]
spaService se = filter ((==se) . getService)
ratedListStr :: Spa -> String
ratedListStr (Spa sid br ar st s) = "\nSpaID: " ++ sid ++ "\n Brand: " ++ br ++ "\n Area: " ++ ar ++ "\n Star: " ++ show st ++ "\n Service Rating" ++ show s
getService
returns a list of Service
s, zo [Service]
, wheras se
is a single Service
, so (==se)
does not make much sense. getService
返回一个Service
列表zo [Service]
,而se
是单个Service
,所以(==se)
没有多大意义。 Since of of the operands is a Service
and the other one is a [Service]
.由于 of 的操作数是一个
Service
而另一个是[Service]
。 Since (==):: Eq a => a -> a -> Bool
acts on two items of the same type, this does not typecheck.由于
(==):: Eq a => a -> a -> Bool
作用于相同类型的两个项目,因此不会进行类型检查。
If you want to check if the se
is for example an element of the services, you can make use of elem:: Foldable f => a -> fa -> Bool
:如果你想检查
se
是否是服务的一个元素,你可以使用elem:: Foldable f => a -> fa -> Bool
:
spaService :: Service -> [Spa] -> [Spa]
spaService se = filter (
elem se . getService)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.