list - Haskell 访问类型类参数问题
问题描述
这很可能是一个简单的问题,但我找不到答案:
如何访问自定义类型的参数?
假设我的代码是这样的:(anotherFunc 只是为了帮助我访问参数)
data Shape = (Shape Color [Dimension])
func :: [Shape] -> [Shape]
func (x:xs) = anotherFunc x : func xs
anotherFunc :: [Shape] -> [Shape]
anotherFunc (Shape Color (x:xs)) = <some simple operations>
有没有类似的东西??
func ( (Shape Color (x:xs)):shapes )
很多谢谢!
解决方案
有一些与此非常相似的东西。
func ((Shape _ (x:xs)):shapes) = ...
但是,您func
只是重新实现map
,因此您可以使用它并继续使用anotherFunc
(如果您愿意,可以在本地定义):
func = map anotherFunc
where anotherFunc (Shape c ds) = ...
推荐阅读
- wicket - 检票口测试中的 PageExpiredException
- javascript - Jest + Playwright - 测试基于事件的 DOM 库的回调
- c# - 循环属性 c#
- c++ - 移动运算符破坏原始指针
- flutter - 在 Flutter 应用程序中加密敏感数据
- javascript - 以不同用户身份运行 Google 表格插件
- python - 使用 OpenCV 计算鸟瞰图
- javascript - Material UI react js中自动完成组件中的默认选择
- c# - 反序列化 JSON 对 C# 对象的响应错误
- selenium - 查找和元素的问题:Selenium 在页面上找不到特定按钮