【问题标题】:Mapping list with function in HaskellHaskell中的函数映射列表
【发布时间】:2017-03-14 16:28:34
【问题描述】:

我是 Haskell 的新手,我正在尝试更改绘制路径的位置。

let redPath =  Path[Point 420 750, Point 420 550] red Solid

drawPicture 10 [redPath, movePictureObject (Vector 100 100)
redPath]

函数 movePictureObject 和 movePoint 应该使用给定向量 (100,100) 更改路径的每个点。

movePoint :: Point -> Vector -> Point
movePoint (Point x y) (Vector xv yv)
  = Point (x + xv) (y + yv)

movePictureObject :: Vector -> PictureObject ->PictureObject
movePictureObject vec (Path points colour lineStyle) 
  = Path map (movePoint (points vec)) red Solid

我不知道如何正确使用地图功能,我在这里阅读了几篇文章并观看了其他教程。

谢谢。

【问题讨论】:

  • 什么是PathPoint 是什么?什么是PictureObjectVector 是什么?为什么这个标签是dictionary?你的实际问题是什么?

标签: haskell


【解决方案1】:

我的水晶球告诉我,你只需要(map movePoint (points vec)) 而不是最后一行的map (movePoint (points vec))

【讨论】:

  • (map (\p -> movePoint p vec) points) 在我看来更有可能。
  • 做到了@Daniel Wagner
猜你喜欢
  • 1970-01-01
  • 2012-09-27
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2018-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多