haskell - 无法将类型“[Char]”与 spa 的“Char”匹配
问题描述
我正在尝试将水疗中心的名称提供给对技能服务进行评分的给定主管以及他们对每个水疗中心的评分结果。但我不断收到如下所示的错误。对不起,如果我的代码看起来很糟糕,因为我是 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)
我尝试为主管检索和过滤。然后我全部输出。是否可以只输出主管名称、水疗中心和等级评级?我走对路了吗?如何修复错误?
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
返回 s, zo 的列表,其中是single ,所以没有多大意义。由于 的操作数是 a而另一个是 a 。由于作用于相同类型的两个项目,因此不会进行类型检查。Service
[Service]
se
Service
(==se)
Service
[Service]
(==) :: Eq a => a -> a -> Bool
如果您想检查是否se
是例如服务的一个元素,您可以使用elem :: Foldable f => a -> f a -> Bool
:
spaService :: Service -> [Spa] -> [Spa]
spaService se = filter (elem se . getService)
推荐阅读
- kubernetes - 无法访问 Openshift 集群中的内部注册表
- outlook - 如何使用 Outlook 插件清单文件在 Outlook 邮件页面和 Outlook 日历页面中添加自定义按钮?
- rust - 如何在 Diesel 中指定多个数据库模式?
- javascript - Gatsby 网站,使用 Helmet 的首页请求中不提供脚本
- reactjs - 单一spa中不同环境的多个importmap.json
- azure - Salesforce - Azure 集成
- java - 如何在Java中将RGB颜色转换为灰度
- python - 如何将数据从一列移动到另一列的行?
- python - ValueError:所有数组的长度必须相同,在数据框中附加数据
- python - col名称相似时添加后缀