Question

I have a function in which I pass in a Point and a Polygon (see type definitions below).

pointIsOnBorder (see below) takes a Point and a Polygon, and determines whether that Point is on one of the borders of the given Polygon.

type Point = (Double, Double)
type Polygon = [Point]

pointIsOnBorder :: Point -> Polygon -> Bool
pointIsOnBorder a ps = if (any onLineSegment(a) (breakPolygonToLines ps)) then True else False

In the above example, breakPolygonToLines correctly takes a list of Points (aka Polygon) and returns a list of Point tuples. Ex: breakPolygonToLines returns [((2.0,3.0),(4.0,3.0)),((4.0,3.0),(5.0,6.0)),((5.0,6.0),(2.0,3.0))] for an input of [(2,3), (4,3), (5, 6)].

From the snippet above, onLineSegment takes a Point and a Point tuple and determines whether the Point exists on the given Point tuple (aka line segment).

onLineSegment :: Point -> (Point, Point) -> Bool

However, I'm experiencing errors by passing in each Point tuple into onLineSegment. Is the syntax any onLineSegment(a) (breakPolygonToLines ps) valid?

Edit: added a lot more details; please see above.

Was it helpful?

Solution

It's hard to answer without knowing what exactly your functions are doing. It seems that any (onLineSegment a) (breakPolygonToLines ps) is what you're looking for. (onLineSegment a) fixes the first argument of the function and gives a function from tuple to Bool.

Relevant wiki page: http://www.haskell.org/haskellwiki/Partial_application

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top