我在 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)