@@ -53,11 +53,13 @@ instance (Ord k, Group q) => Group (MonoidalMap k q) where
54instance (Ord k, Additive q) => Additive (MonoidalMap k q)
54instance (Ord k, Additive q) => Additive (MonoidalMap k q)
56instance Group () where
57instance Group () where
57 negateG _ = ()
58 negateG _ = ()
58 _ ~~ _ = ()
59 _ ~~ _ = ()
59instance Additive ()
60instance Additive ()
62+-- | Product group. A Pair of groups gives rise to a group
61instance (Group a, Group b) => Group (a, b) where
63instance (Group a, Group b) => Group (a, b) where
62 negateG (a, b) = (negateG a, negateG b)
64 negateG (a, b) = (negateG a, negateG b)
63 (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
65 (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
@@ -71,21 +73,26 @@ instance Group (f (g a)) => Group ((f :.: g) a) where
71 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
73 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
72instance Additive (f (g a)) => Additive ((f :.: g) a)
74instance Additive (f (g a)) => Additive ((f :.: g) a)
76+-- | Product of groups, Functor style.
74instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
77instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
75 negateG (a :*: b) = negateG a :*: negateG b
78 negateG (a :*: b) = negateG a :*: negateG b
76 (a :*: b) ~~ (c :*: d) = (a ~~ c :*: b ~~ d)
79 (a :*: b) ~~ (c :*: d) = (a ~~ c :*: b ~~ d)
77instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
80instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
82+-- | Trivial group, Functor style
79instance Group (Proxy x) where
83instance Group (Proxy x) where
80 negateG _ = Proxy
84 negateG _ = Proxy
81 _ ~~ _ = Proxy
85 _ ~~ _ = Proxy
82instance Additive (Proxy x)
86instance Additive (Proxy x)
88+-- | Const lifts groups into a functor.
84deriving instance Group a => Group (Const a x)
89deriving instance Group a => Group (Const a x)
85instance Additive a => Additive (Const a x)
90instance Additive a => Additive (Const a x)
91+-- | Ideitnty lifts groups pointwise (at only one point)
86deriving instance Group a => Group (Identity a)
92deriving instance Group a => Group (Identity a)
87instance Additive a => Additive (Identity a)
93instance Additive a => Additive (Identity a)
95+-- | Functions lift groups pointwise.
89instance Group b => Group (a -> b) where
96instance Group b => Group (a -> b) where
90 negateG f = negateG . f
97 negateG f = negateG . f
91 (~~) = liftA2 (~~)
98 (~~) = liftA2 (~~)