polygon :: [Coordinate] -> Region

polygon x

| (length x) < 3 = error "polygon: requires at least 3 points"

| otherwise = halfPlane (head x) (tail x ++ [head x])

where halfPlane x1 (x2:xs) = HalfPlane x1 x2 `Intersect` halfPlane x2 xs

halfPlane _ [] = Complement Empty

Jon – assuming there is no polygon with less than 3 sides then the check should return error and not Empty. ]]>

polygon ver =

foldl Intersect Empty [HalfPlane a b| (a,b)<-zip ver (tail ver++[head ver])]

it should be

polygon ver =

foldl Intersect (Complement Empty) [HalfPlane a b| (a,b)<-zip ver (tail ver++[head ver])]

beacause “anything `Intersect` Empty” is “Empty”. You should Intersect it with all the space which is “Complement Empty”. I wrote the same solution with “Complement Empty” and it is working.

]]>http://www.mroweczka.pl/exerc806.hs

polygon ver = foldl Intersect Empty [HalfPlane a b| (a,b)< -zip ver (tail ver++[head ver])]

or if you don't like Empty constructor

polygon' ver = let zipped = [HalfPlane a b| (a,b)< -zip ver (tail ver++[head ver])] in foldl Intersect (head zipped) (tail zipped)

[Edited by admin to add code from the above URL]

]]>