license: Add copyright and license information.
[altfloat.git] / Data / Poset.hs
blobd306eec67507da20e160ae4e99774ddc0f708555
1 {-
2 - Copyright (C) 2009 Nick Bowler.
4 - License BSD2: 2-clause BSD license. See LICENSE for full terms.
5 - This is free software: you are free to change and redistribute it.
6 - There is NO WARRANTY, to the extent permitted by law.
7 -}
9 module Data.Poset (
10 Poset(..), Sortable(..), Ordering(..),
11 module Data.Poset
12 ) where
14 import Prelude hiding (Ord(..), Ordering(..))
15 import Data.Poset.Internal
17 import Data.Function
18 import Data.Monoid
20 instance Poset a => Poset (Maybe a) where
21 Just x <= Just y = x <= y
22 Nothing <= _ = True
23 _ <= _ = False
25 instance Poset a => Poset [a] where
26 compare = (mconcat .) . zipWith compare
28 -- | Sort a list using the default comparison function.
29 sort :: Sortable a => [a] -> [a]
30 sort = sortBy compare
32 -- | Apply a function to values before comparing.
33 comparing :: Poset b => (a -> b) -> a -> a -> Ordering
34 comparing = on compare