{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Safe #-}
-----------------------------------------------------------------------------
-- |
-- Copyright   :  (C) 2011-2015 Edward Kmett
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
-- Stability   :  provisional
-- Portability :  polykinds
--
----------------------------------------------------------------------------

module Data.Isomorphism
  ( Iso(..)
  ) where

import Control.Category
import Data.Semigroupoid
import Data.Groupoid
import Prelude ()

data Iso k a b = Iso { forall {k} (k :: k -> k -> *) (a :: k) (b :: k). Iso k a b -> k a b
embed :: k a b, forall {k} (k :: k -> k -> *) (a :: k) (b :: k). Iso k a b -> k b a
project :: k b a }

instance Semigroupoid k => Semigroupoid (Iso k) where
  Iso k j k
f k k j
g o :: forall (j :: k) (k :: k) (i :: k).
Iso k j k -> Iso k i j -> Iso k i k
`o` Iso k i j
h k j i
i = forall {k} (k :: k -> k -> *) (a :: k) (b :: k).
k a b -> k b a -> Iso k a b
Iso (k j k
f forall {k} (c :: k -> k -> *) (j :: k) (k :: k) (i :: k).
Semigroupoid c =>
c j k -> c i j -> c i k
`o` k i j
h) (k j i
i forall {k} (c :: k -> k -> *) (j :: k) (k :: k) (i :: k).
Semigroupoid c =>
c j k -> c i j -> c i k
`o` k k j
g)

instance Semigroupoid k => Groupoid (Iso k) where
  inv :: forall (a :: k) (b :: k). Iso k a b -> Iso k b a
inv (Iso k a b
f k b a
g) = forall {k} (k :: k -> k -> *) (a :: k) (b :: k).
k a b -> k b a -> Iso k a b
Iso k b a
g k a b
f

instance Category k => Category (Iso k) where
  Iso k b c
f k c b
g . :: forall (b :: k) (c :: k) (a :: k).
Iso k b c -> Iso k a b -> Iso k a c
. Iso k a b
h k b a
i = forall {k} (k :: k -> k -> *) (a :: k) (b :: k).
k a b -> k b a -> Iso k a b
Iso (k b c
f forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. k a b
h) (k b a
i forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. k c b
g)
  id :: forall (a :: k). Iso k a a
id = forall {k} (k :: k -> k -> *) (a :: k) (b :: k).
k a b -> k b a -> Iso k a b
Iso forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id