生成行

时间:2018-03-30 13:36:15

标签: haskell

这是我的尝试:

getLineGraphic :: Point -> Point -> ColourName -> Graphic
getLineGraphic a b colourType = (Graphic (Line(a b) colourType (0,0)))

Shape

定义
data Shape = Rectangle Side Side
       | Ellipse   Side Side
       | Polygon   [Point]
       | Line      Point Point
deriving (Show)

ColourName

data ColourName
= Magenta
| Black
| Green
| Yellow
| Orange
| Cyan
deriving (Show)

这是我得到的错误:

src\View.hs:54:34: error:
    * Couldn't match expected type `Graphic'
                  with actual type `ColourName -> Point -> Graphic'
    * Probable cause: `Graphic' is applied to too few arguments
      In the expression: (Graphic (Line (a b) colourType (0, 0)))
      In an equation for `getLineGraphic':
          getLineGraphic a b colourType
            = (Graphic (Line (a b) colourType (0, 0)))
   |
54 | getLineGraphic a b colourType = (Graphic (Line(a b) colourType (0,0)))

最重要的是我的尝试。不知道我哪里出错了?对于这部分,翻译必须是{​​{1}},这就是为什么会出现这种情况。不知道为什么我会收到此错误?任何帮助,将不胜感激!感谢。

1 个答案:

答案 0 :(得分:3)

虽然您没有发布MCVE,但我只能猜出原因,

(Graphic (Line(a b) colourType (0,0)))

这似乎是错误的。你可能想要

(Graphic (Line a b) colourType (0,0))

说明:就像函数一样,Haskell中的数据构造函数是curry。所以

Line a b

相同
((Line a) b)

完全不同
Line (a b)