module OAlg.Data.Ord
(
module Ord
, fcompare, wcompare, coCompare, compare2
, sortFst, sortFstBy, sortSnd, sortSndBy
, Closer(..), cmin, cmax, cspan, Span, enumSpan
, POrd(..)
)
where
import Data.List (sortBy)
import Data.Ord as Ord
fcompare :: Ord i => (a -> i) -> a -> a -> Ordering
fcompare :: forall i a. Ord i => (a -> i) -> a -> a -> Ordering
fcompare a -> i
f a
x a
y = forall a. Ord a => a -> a -> Ordering
compare (a -> i
f a
x) (a -> i
f a
y)
wcompare :: (w -> w -> Ordering) -> (a -> w) -> a -> a -> Ordering
wcompare :: forall w a. (w -> w -> Ordering) -> (a -> w) -> a -> a -> Ordering
wcompare w -> w -> Ordering
cmp a -> w
f a
x a
y = w -> w -> Ordering
cmp (a -> w
f a
x) (a -> w
f a
y)
coCompare :: (a -> a -> Ordering) -> a -> a -> Ordering
coCompare :: forall a. (a -> a -> Ordering) -> a -> a -> Ordering
coCompare a -> a -> Ordering
cmp a
x a
y = a -> a -> Ordering
cmp a
y a
x
compare2 :: (a -> a -> Ordering) -> (b -> b -> Ordering) -> (a,b) -> (a,b) -> Ordering
compare2 :: forall a b.
(a -> a -> Ordering)
-> (b -> b -> Ordering) -> (a, b) -> (a, b) -> Ordering
compare2 a -> a -> Ordering
acmp b -> b -> Ordering
bcmp (a
a,b
b) (a
a',b
b') = case a
a a -> a -> Ordering
`acmp` a
a' of
Ordering
EQ -> b
b b -> b -> Ordering
`bcmp` b
b'
Ordering
o -> Ordering
o
sortFstBy :: (a -> a -> Ordering) -> [(a,b)] -> [(a,b)]
sortFstBy :: forall a b. (a -> a -> Ordering) -> [(a, b)] -> [(a, b)]
sortFstBy a -> a -> Ordering
cmp = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall w a. (w -> w -> Ordering) -> (a -> w) -> a -> a -> Ordering
wcompare a -> a -> Ordering
cmp forall a b. (a, b) -> a
fst)
sortFst :: Ord a => [(a,b)] -> [(a,b)]
sortFst :: forall a b. Ord a => [(a, b)] -> [(a, b)]
sortFst = forall a b. (a -> a -> Ordering) -> [(a, b)] -> [(a, b)]
sortFstBy forall a. Ord a => a -> a -> Ordering
compare
sortSndBy :: (b -> b -> Ordering) -> [(a,b)] -> [(a,b)]
sortSndBy :: forall b a. (b -> b -> Ordering) -> [(a, b)] -> [(a, b)]
sortSndBy b -> b -> Ordering
cmp = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall w a. (w -> w -> Ordering) -> (a -> w) -> a -> a -> Ordering
wcompare b -> b -> Ordering
cmp forall a b. (a, b) -> b
snd)
sortSnd :: Ord b => [(a,b)] -> [(a,b)]
sortSnd :: forall b a. Ord b => [(a, b)] -> [(a, b)]
sortSnd = forall b a. (b -> b -> Ordering) -> [(a, b)] -> [(a, b)]
sortSndBy forall a. Ord a => a -> a -> Ordering
compare
data Closer x
= NegInf
| It x
| PosInf
deriving (Int -> Closer x -> ShowS
forall x. Show x => Int -> Closer x -> ShowS
forall x. Show x => [Closer x] -> ShowS
forall x. Show x => Closer x -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Closer x] -> ShowS
$cshowList :: forall x. Show x => [Closer x] -> ShowS
show :: Closer x -> String
$cshow :: forall x. Show x => Closer x -> String
showsPrec :: Int -> Closer x -> ShowS
$cshowsPrec :: forall x. Show x => Int -> Closer x -> ShowS
Show,ReadPrec [Closer x]
ReadPrec (Closer x)
ReadS [Closer x]
forall x. Read x => ReadPrec [Closer x]
forall x. Read x => ReadPrec (Closer x)
forall x. Read x => Int -> ReadS (Closer x)
forall x. Read x => ReadS [Closer x]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Closer x]
$creadListPrec :: forall x. Read x => ReadPrec [Closer x]
readPrec :: ReadPrec (Closer x)
$creadPrec :: forall x. Read x => ReadPrec (Closer x)
readList :: ReadS [Closer x]
$creadList :: forall x. Read x => ReadS [Closer x]
readsPrec :: Int -> ReadS (Closer x)
$creadsPrec :: forall x. Read x => Int -> ReadS (Closer x)
Read,Closer x -> Closer x -> Bool
forall x. Eq x => Closer x -> Closer x -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Closer x -> Closer x -> Bool
$c/= :: forall x. Eq x => Closer x -> Closer x -> Bool
== :: Closer x -> Closer x -> Bool
$c== :: forall x. Eq x => Closer x -> Closer x -> Bool
Eq,Closer x -> Closer x -> Bool
Closer x -> Closer x -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {x}. Ord x => Eq (Closer x)
forall x. Ord x => Closer x -> Closer x -> Bool
forall x. Ord x => Closer x -> Closer x -> Ordering
forall x. Ord x => Closer x -> Closer x -> Closer x
min :: Closer x -> Closer x -> Closer x
$cmin :: forall x. Ord x => Closer x -> Closer x -> Closer x
max :: Closer x -> Closer x -> Closer x
$cmax :: forall x. Ord x => Closer x -> Closer x -> Closer x
>= :: Closer x -> Closer x -> Bool
$c>= :: forall x. Ord x => Closer x -> Closer x -> Bool
> :: Closer x -> Closer x -> Bool
$c> :: forall x. Ord x => Closer x -> Closer x -> Bool
<= :: Closer x -> Closer x -> Bool
$c<= :: forall x. Ord x => Closer x -> Closer x -> Bool
< :: Closer x -> Closer x -> Bool
$c< :: forall x. Ord x => Closer x -> Closer x -> Bool
compare :: Closer x -> Closer x -> Ordering
$ccompare :: forall x. Ord x => Closer x -> Closer x -> Ordering
Ord)
cmax :: Ord x => [x] -> Closer x
cmax :: forall x. Ord x => [x] -> Closer x
cmax [] = forall x. Closer x
NegInf
cmax (x
x:[x]
xs) = forall a. Ord a => a -> a -> a
max (forall x. x -> Closer x
It x
x) (forall x. Ord x => [x] -> Closer x
cmax [x]
xs)
cmin :: Ord x => [x] -> Closer x
cmin :: forall x. Ord x => [x] -> Closer x
cmin [] = forall x. Closer x
PosInf
cmin (x
x:[x]
xs) = forall a. Ord a => a -> a -> a
min (forall x. x -> Closer x
It x
x) (forall x. Ord x => [x] -> Closer x
cmin [x]
xs)
type Span x = (Closer x,Closer x)
cspan :: Ord x => [x] -> Span x
cspan :: forall x. Ord x => [x] -> Span x
cspan [] = (forall x. Closer x
PosInf,forall x. Closer x
NegInf)
cspan (x
x:[x]
xs) = (forall a. Ord a => a -> a -> a
min (forall x. x -> Closer x
It x
x) Closer x
l,forall a. Ord a => a -> a -> a
max (forall x. x -> Closer x
It x
x) Closer x
u) where (Closer x
l,Closer x
u) = forall x. Ord x => [x] -> Span x
cspan [x]
xs
enumSpan :: (Enum i, Ord i) => i -> Closer i -> [i]
enumSpan :: forall i. (Enum i, Ord i) => i -> Closer i -> [i]
enumSpan i
i0 Closer i
h | Closer i
h forall a. Ord a => a -> a -> Bool
< forall x. x -> Closer x
It i
i0 = []
enumSpan i
i0 Closer i
PosInf = [i
i0..]
enumSpan i
i0 (It i
h) = [i
i0..i
h]
enumSpan i
_ Closer i
NegInf = []
class Eq a => POrd a where
infix 4 <<=
(<<=) :: a -> a -> Bool