Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added indexed groups by applicative from #haskell.

  • Loading branch information...
commit 3cc4093a1179ce100357bd1a9a6dd9fb93ba3cd6 1 parent b9c251a
@ekmett authored
Showing with 35 additions and 0 deletions.
  1. +1 −0  indexed.cabal
  2. +34 −0 src/Indexed/Group.hs
View
1  indexed.cabal
@@ -36,6 +36,7 @@ library
Indexed.Coproduct
Indexed.Foldable
Indexed.Functor
+ Indexed.Group
Indexed.Monad.Free
Indexed.Monoid
Indexed.Product
View
34 src/Indexed/Group.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE GADTs #-}
+module Indexed.Group
+ ( Group(..)
+ , Groupoid(..)
+ , IGroup(..)
+ ) where
+
+import Indexed.Types
+import Indexed.Monoid
+import Data.Monoid
+
+class Monoid m => Group m where
+ -- | @'inv' '.' 'inv' = 'id'@
+ inv :: m -> m
+
+class Cat k => Groupoid k where
+ -- | @'invert' '.' 'invert' = 'idd'@
+ invert :: k i j -> k j i
+
+class IMonoid m => IGroup m where
+ -- | @'iinv' '.' 'iinv' = 'imempty'@
+ iinv :: m '(i,j) -> m '(j,i)
+
+-- | A 'Groupoid' is an indexed group
+instance Groupoid k => IGroup (Morphism k) where
+ iinv (Morphism f) = Morphism (invert f)
+
+instance Group m => Groupoid (At m) where
+ invert (At m) = At (inv m)
+
+instance Groupoid (==) where
+ invert Refl = Refl
Please sign in to comment.
Something went wrong with that request. Please try again.