繁体   English   中英

Haskell 访问类型类参数问题

[英]Haskell accessing type-classes parameters problem

这可能是一个简单的问题,但我找不到答案:

如何访问自定义类型的参数?

假设我的代码是这样的:(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) = ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM