0N/ADescription : support for partial orders
0N/ACopyright : (c) Keith Wansbrough 200 and Uni Bremen 2005
0N/ALicense : GPLv2 or higher
0N/AMaintainer : Christian.Maeder@dfki.de
0N/AStability : provisional
0N/APortability : portable
0N/ASupport for partial orders
0N/A-- | the partial order relation type
0N/Atype POrder a = a -> a -> Maybe Ordering
553N/A-- Ord a implies a total order
553N/AtotalOrder :: Ord a => POrder a
0N/AtotalOrder x = Just . compare x
0N/A-- | split a list of elements into equivalence classes
0N/AequivBy :: POrder a -> [a] -> [[a]]
0N/AequivBy order l = equiv0 [] l where
c@(y : _) : r -> case order x y of
-- | split a set into the minimal elements and the remaining elements
minimalBy :: POrder a -> [a] -> ([a], [a])
minimalBy order es = go es [] [] where
[] -> (reverse ms, reverse rs)
if any (\ e -> order x e == Just GT) es
-- | split a set into ranks of elements, minimal first
rankBy :: POrder a -> [a] -> [[a]]
rankBy order l = case l of
_ -> let (xs, ys) = minimalBy order l in
-- | A partial-ordering class.
then if b <=? a then Just EQ else Just LT
else if b <=? a then Just GT else Nothing
a <=? b = case pCmp a b of
equiv :: Partial a => [a] -> [[a]]
minimal :: Partial a => [a] -> ([a], [a])
rank :: Partial a => [a] -> [[a]]
instance Ord a => Partial a where