該代碼需要一個四叉樹並插入一個矩形。但是,我得到一個語法分析錯誤。我想調用函數newExtent而不必添加所有參數。所以newExtent TopLeft
而不必撥打newExtent TopLeft extent rectangle
。我如何使它工作?解析輸入錯誤'let'
insert :: QuadTree -> Rectangle -> QuadTree
insert (Qt extent horizontal vertical qTL qTR qBL qBR) rectangle
| quadPart extent rectangle == VerLine = Qt extent horizontal (rectangle:vertical) qTL qTR qBL qBR
| quadPart extent rectangle == HorLine = Qt extent (rectangle:horizontal) vertical qTL qTR qBL qBR
| quadPart extent rectangle == TopLeft && qTL == EmptyQuadTree = Qt extent horizontal vertical (newExtent TopLeft) qTR qBL qBR
| quadPart extent rectangle == TopLeft = Qt extent horizontal vertical (insert qTL rectangle) qTR qBL qBR
| quadPart extent rectangle == TopRight && qTR == EmptyQuadTree = Qt extent horizontal vertical qTL (newExtent TopRight) qBL qBR
| quadPart extent rectangle == TopRight = Qt extent horizontal vertical qTL (insert qTR rectangle) qBL qBR
| quadPart extent rectangle == BottomLeft && qBL == EmptyQuadTree = Qt extent horizontal vertical qTL qTR (newExtent BottomLeft) qBR
| quadPart extent rectangle == BottomLeft = Qt extent horizontal vertical qTL qTR (insert qBL rectangle) qBR
| quadPart extent rectangle == BottomRight && qBR == EmptyQuadTree = Qt extent horizontal vertical qTL qTR qBL (newExtent BottomRight)
| otherwise = Qt extent horizontal vertical qTL qTR qBL (insert qBR rectangle)
let (Rect eL eT eR eB) = extent
in newExtent :: TreeParts -> Rectangle -> Rectangle -> QuadTree
newExtent part (Rect eL eT eR eB) rectangle
| part == TopLeft = insert (emptyQtree (Rect eL eT ((eL + eR) `div` 2) ((eT + eB) `div` 2))) rectangle
| part == TopRight = insert (emptyQtree (Rect ((eL + eR) `div` 2) eT eR ((eT + eB) `div` 2))) rectangle
| part == BottomLeft = insert (emptyQtree (Rect eL ((eT + eB) `div` 2) ((eL + eR) `div` 2) eB)) rectangle
| part == BottomRight = insert (emptyQtree (Rect ((eL + eR) `div` 2) ((eT + eB) `div` 2) eR eB)) rectangle
更換您的讓利塊*請*閱讀[哈斯克爾教程(http://stackoverflow.com/a/1016986/925978)。你不能在'let'語句中輸入一個類型簽名。 – crockeea 2015-02-07 14:20:20
謝謝,我修正了,但我仍然得到相同的錯誤... – quackAttack 2015-02-07 14:22:38