小编Joh*_*ohn的帖子

Purescript 类型不统一

我在 Purescript 文件中定义了几种类型:

data Point = Point {
  x :: Int,
  y :: Int
}

data Rect = Rect {
  upperLeft :: Point,
  upperRight :: Point,
  lowerLeft :: Point,
  lowerRight :: Point
}
Run Code Online (Sandbox Code Playgroud)

现在我想定义一个函数来检查两个矩形是否重叠:

rectsOverlap :: Rect -> Rect -> Boolean
rectsOverlap r s = (r.upperLeft.x > s.lowerRight.x && r.upperLeft.y > s.lowerRight.y)
  || (r.upperLeft.x < s.lowerRight.x && r.upperLeft.y < s.lowerRight.y)
  || (r.lowerLeft.x > s.upperRight.x && r.lowerLeft.y > s.upperRight.y)
  || (r.lowerLeft.x < s.upperRight.x && r.lowerLeft.y < s.upperRight.y)
Run Code Online (Sandbox Code Playgroud)

但是,这会导致以下错误:

  Could not match …
Run Code Online (Sandbox Code Playgroud)

types typeerror purescript

3
推荐指数
1
解决办法
229
查看次数

标签 统计

purescript ×1

typeerror ×1

types ×1