2{-# LANGUAGE DefaultSignatures #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE StandaloneDeriving #-}
5{-# LANGUAGE TypeOperators #-}
7-- TODO upstream somwhere else?
8module Data.Monoid.DecidablyEmpty where
10import Data.Functor.Identity
11import Data.Functor.Const
13import Data.Maybe (isNothing)
14#if MIN_VERSION_base(4,11,0)
18import Data.Semigroup hiding (First, Last)
19#if MIN_VERSION_base(4,12,0)
23import qualified Data.IntSet as IntSet
24import qualified Data.IntMap as IntMap
25import qualified Data.Map as Map
26import qualified Data.Sequence as Seq
27import qualified Data.Set as Set
29import Data.GADT.Compare
30import qualified Data.Dependent.Map as DMap
32-- | A 'DecidablyEmpty' is one where it can be computed whether or not an
33-- arbitrary value is 'mempty'.
35-- By using this class rather than 'Eq', we avoid unnecessary constraining the
36-- contents of 'Functor's. This makes it possible to efficiently combine and/or
37-- nest patch maps with 'Eq'-lacking values (e.g. functions) at the leaves.
38class Monoid a => DecidablyEmpty a where
40 default isEmpty :: Eq a => a -> Bool
45instance DecidablyEmpty Ordering
46instance DecidablyEmpty ()
47instance DecidablyEmpty Any
48instance DecidablyEmpty All
49-- instance DecidablyEmpty Lifetime
50-- instance DecidablyEmpty Event
51instance DecidablyEmpty [a] where
54#if MIN_VERSION_base(4,11,0)
59 => DecidablyEmpty (Maybe a) where
61deriving instance (Num a, DecidablyEmpty a) => DecidablyEmpty (Product a)
62deriving instance (DecidablyEmpty a, Num a) => DecidablyEmpty (Sum a)
63deriving instance DecidablyEmpty a => DecidablyEmpty (Dual a)
64instance DecidablyEmpty (First a) where
65 isEmpty (First a) = isNothing a
66instance DecidablyEmpty (Last a) where
67 isEmpty (Last a) = isNothing a
68deriving instance DecidablyEmpty a => DecidablyEmpty (Identity a)
69instance Semigroup a => DecidablyEmpty (Option a) where
70 isEmpty (Option a) = isNothing a
71deriving instance DecidablyEmpty m => DecidablyEmpty (WrappedMonoid m)
72instance (Ord a, Bounded a) => DecidablyEmpty (Max a)
73instance (Ord a, Bounded a) => DecidablyEmpty (Min a)
74instance DecidablyEmpty (Proxy s)
75deriving instance DecidablyEmpty a => DecidablyEmpty (Const a b)
76#if MIN_VERSION_base(4,11,0)
77deriving instance DecidablyEmpty a => DecidablyEmpty (Down a)
79#if MIN_VERSION_base(4,12,0)
80deriving instance DecidablyEmpty p => DecidablyEmpty (Par1 p)
81instance DecidablyEmpty (U1 p)
82deriving instance DecidablyEmpty (f p) => DecidablyEmpty (Rec1 f p)
83deriving instance DecidablyEmpty (f p) => DecidablyEmpty (M1 i c f p)
84deriving instance DecidablyEmpty c => DecidablyEmpty (K1 i c p)
85instance (DecidablyEmpty (f p), DecidablyEmpty (g p)) => DecidablyEmpty ((f :*: g) p) where
86 isEmpty (x :*: y) = isEmpty x && isEmpty y
87deriving instance DecidablyEmpty (f (g p)) => DecidablyEmpty ((f :.: g) p)
90instance (DecidablyEmpty a, DecidablyEmpty b) => DecidablyEmpty (a, b) where
91 isEmpty (a, b) = isEmpty a && isEmpty b
92instance (DecidablyEmpty a, DecidablyEmpty b, DecidablyEmpty c) => DecidablyEmpty (a, b, c) where
93 isEmpty (a, b, c) = isEmpty a && isEmpty b && isEmpty c
94instance (DecidablyEmpty a, DecidablyEmpty b, DecidablyEmpty c, DecidablyEmpty d) => DecidablyEmpty (a, b, c, d) where
95 isEmpty (a, b, c, d) = isEmpty a && isEmpty b && isEmpty c && isEmpty d
96instance (DecidablyEmpty a, DecidablyEmpty b, DecidablyEmpty c, DecidablyEmpty d, DecidablyEmpty e) => DecidablyEmpty (a, b, c, d, e) where
97 isEmpty (a, b, c, d, e) = isEmpty a && isEmpty b && isEmpty c && isEmpty d && isEmpty e
101instance DecidablyEmpty IntSet.IntSet where
102 isEmpty = IntSet.null
103instance DecidablyEmpty (IntMap.IntMap v) where
104 isEmpty = IntMap.null
105instance Ord k => DecidablyEmpty (Map.Map k v) where
107instance DecidablyEmpty (Seq.Seq v) where
109instance Ord k => DecidablyEmpty (Set.Set k) where
114instance GCompare k => DecidablyEmpty (DMap.DMap k v) where
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list