license: Fix copyright years in source files.
[altfloat.git] / Data / Poset / Instances.hs
blob44c8c95a2c64059614d6da493c68a0661b644666
1 {-
2 - Copyright (C) 2009-2010 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 -- | 'Poset' and 'Sortable' instances for instances of 'Prelude.Ord'
10 {-# LANGUAGE CPP #-}
11 module Data.Poset.Instances where
13 import qualified Data.Poset.Internal as Poset
14 import Data.Poset.Internal (Poset, Sortable, partialOrder, totalOrder)
16 import Data.Ratio
17 import Data.List
18 import Data.Word
19 import Data.Int
21 #define POSET_ORD_INSTANCE(ctx, v) instance ctx Poset (v) where { \
22 compare = (partialOrder .) . compare; \
23 (<) = (<); \
24 (<=) = (<=); \
25 (>=) = (>=); \
26 (>) = (>); \
27 (<==>) = const $ const True; \
28 (</=>) = const $ const False }
30 #define SORTABLE_ORD_INSTANCE(ctx, v) instance ctx Sortable (v) where { \
31 isOrdered = const True; \
32 sortBy f = sortBy $ (totalOrder .) . f; \
33 max = max; \
34 min = min; }
36 #define ORD_INSTANCE(ctx, v) \
37 POSET_ORD_INSTANCE(ctx, v); \
38 SORTABLE_ORD_INSTANCE(ctx, v); \
39 instance ctx Poset.Ord (v)
41 ORD_INSTANCE(, Bool)
42 ORD_INSTANCE(, Char)
43 ORD_INSTANCE(, Int)
44 ORD_INSTANCE(, Int8)
45 ORD_INSTANCE(, Int16)
46 ORD_INSTANCE(, Int32)
47 ORD_INSTANCE(, Int64)
48 ORD_INSTANCE(, Word)
49 ORD_INSTANCE(, Word8)
50 ORD_INSTANCE(, Word16)
51 ORD_INSTANCE(, Word32)
52 ORD_INSTANCE(, Word64)
53 ORD_INSTANCE(, Integer)
55 ORD_INSTANCE(Integral a =>, Ratio a)