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.
9 -- | Partially ordered data types. The standard 'Prelude.Ord' class is for
10 -- total orders and therefore not suitable for floating point. However, we can
11 -- still define meaningful 'max' and 'sort' functions for these types.
13 -- We define our own 'Ord' class which is intended as a replacement for
14 -- 'Prelude.Ord'. However, in order to take advantage of existing libraries
15 -- which use 'Prelude.Ord', we make every instance of 'Ord' an instance of
16 -- 'Prelude.Ord'. This is done using the OverlappingInstances and
17 -- UndecidableInstances extensions -- it remains to be seen if problems occur
18 -- as a result of this.
20 Poset
(..), Sortable
(..), Ordering(..), Ord
,
24 import Prelude
hiding (Ord
(..), Ordering(..))
25 import Data
.Poset
.Instances
26 import Data
.Poset
.Internal
31 instance Poset a
=> Poset
(Maybe a
) where
32 Just x
<= Just y
= x
<= y
36 instance Poset a
=> Poset
[a
] where
37 compare = (mconcat
.) . zipWith compare
39 -- | Sort a list using the default comparison function.
40 sort :: Sortable a
=> [a
] -> [a
]
43 -- | Apply a function to values before comparing.
44 comparing
:: Poset b
=> (a
-> b
) -> a
-> a
-> Ordering
45 comparing
= on
compare