-- a EQ b if there is no rule about the order of a and b
pageOrder :: Rules -> Page -> Page -> Ordering
pageOrder rules a b
- | isNothing pa && isNothing pb = EQ
- | isNothing pa = LT
- | isNothing pb = GT
| S.member a rb = LT
| S.member b ra = GT
| otherwise = EQ
- where pa = rules M.!? a
- pb = rules M.!? b
- ra = fromJust pa
- rb = fromJust pb
-
+ where ra = M.findWithDefault S.empty a rules
+ rb = M.findWithDefault S.empty b rules
middlePage :: [Page] -> Page
middlePage b = b !! (length b `div` 2)