adjust :: [(Color, Region)] -> Coordinate -> (Maybe (Color, Region), [(Color, Region)])
adjust regs p
= case (break (\(_, r) -> r `containsR` p) regs) of
(top, hit:rest) -> (Just hit, top ++ rest)
(_, []) -> (Nothing, regs)
loop0 :: Window -> [(Color, Region)] -> IO ()
loop0 w regs = do
clearWindow w
sequence_ [drawRegionInWindow w c r | (c, r) <- reverse regs]
(x, y) <- getLBP w
case (adjust regs (pixelToInch (x - xWin2), pixelToInch (yWin2 - y))) of
(Nothing, _) -> closeWindow w
(Just hit, newRegs) -> loop0 w (hit : newRegs)
loop w regs = do
clearWindow w
sequence_ (map (uncurry (drawRegionInWindow w)) (reverse regs))
(x, y) <- getLBP w
let aux (_, r) = r `containsR` (pixelToInch (x - xWin2), pixelToInch (yWin2 - y))
case (break aux regs) of
(_, []) -> closeWindow w
(top, hit:bot) -> loop w (hit:(top++bot))
{-
Prove loop0 == loop
because:
uncurry :: (a -> b -> c) -> (a,b) -> c
so the 2 blow are the same:
sequence_ [drawRegionInWindow w c r | (c, r) <- reverse regs]
sequence_ (map (uncurry (drawRegionInWindow w)) (reverse regs))
and
the aux function is almost the same as anonymous function
inside the case of adjut function with p replace the value pass later.
-}
This entry was posted
on Sunday, June 10th, 2007 at 12:32 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.