【发布时间】:2018-10-12 05:22:47
【问题描述】:
rectangleRaster :: Coord -> Coord -> Raster
rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
矩形由两点定义:
data Shape
= Point Point
| Rectangle Point
Point
| Circle Point
Point
| Line Point
Point
| Polygon [Point]
deriving (Show)
而Point被定义为
type Point = (Double, Double)
地点:
type Shade = Double
type Coord = (Int, Int)
和
type Pixel = (Coord, Shade)
type Raster = [Pixel]
错误:
src\View.hs:70:24: error:
* Couldn't match type `Shape' with `[Pixel]'
Expected type: Raster
Actual type: Shape
* In the expression: (Rectangle [(a, 1)] [(b, 1)])
In an equation for `rectangleRaster':
rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
|
70 | rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
src\View.hs:70:34: error:
* Couldn't match type `[(Coord, Integer)]' with `(Double, Double)'
Expected type: Point
Actual type: [(Coord, Integer)]
* In the first argument of `Rectangle', namely `[(a, 1)]'
In the expression: (Rectangle [(a, 1)] [(b, 1)])
In an equation for `rectangleRaster':
rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
|
70 | rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
| ^^^^^^^^
src\View.hs:70:43: error:
* Couldn't match type `[(Coord, Integer)]' with `(Double, Double)'
Expected type: Point
Actual type: [(Coord, Integer)]
* In the second argument of `Rectangle', namely `[(b, 1)]'
In the expression: (Rectangle [(a, 1)] [(b, 1)])
In an equation for `rectangleRaster':
rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
|
70 | rectangleRaster a b = (Rectangle [(a, 1)] [(b, 1)])
|
不确定我做错了什么?这可能与 Raster 作为 [Pixel] 的列表有关,如果是这样,有人可以帮我解决这个问题吗?谢谢!
【问题讨论】:
-
您似乎不太了解
type和data之间的区别。Raster、Shade和Coord只存在于类型级别,它们只是现有类型的别名 -
是的,我在发帖时意识到了这一点。我已将帖子编辑为我尝试过的内容,但仍然出现错误。抱歉,我是 Haskell 的新手,我犯了一些愚蠢的错误。
标签: haskell types compiler-errors type-mismatch algebraic-data-types