{-# OPTIONS_HADDOCK show-extensions #-}
module IsomorphismClass.Isomorphism
( Isomorphism,
iso,
)
where
import Control.Applicative (pure)
import Control.Arrow (Kleisli (Kleisli))
import Control.Category ((.))
import Control.Comonad (Cokleisli (Cokleisli), Comonad, extract)
import Control.Monad (Monad)
import GHC.Base (Type)
import IsomorphismClass (IsomorphicTo, from, to)
import Prelude (($))
class Isomorphism (c :: Type -> Type -> Type) where
iso :: IsomorphicTo a b => c a b
instance Isomorphism (->) where
iso :: IsomorphicTo a b => a -> b
iso :: a -> b
iso = a -> b
forall a b. IsomorphicTo b a => a -> b
from
instance Monad m => Isomorphism (Kleisli m) where
iso :: IsomorphicTo a b => Kleisli m a b
iso :: Kleisli m a b
iso = (a -> m b) -> Kleisli m a b
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((a -> m b) -> Kleisli m a b) -> (a -> m b) -> Kleisli m a b
forall a b. (a -> b) -> a -> b
$ b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> (a -> b) -> a -> m b
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> b
forall a b. IsomorphicTo a b => b -> a
to
instance Comonad w => Isomorphism (Cokleisli w) where
iso :: IsomorphicTo a b => Cokleisli w a b
iso :: Cokleisli w a b
iso = (w a -> b) -> Cokleisli w a b
forall k (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli ((w a -> b) -> Cokleisli w a b) -> (w a -> b) -> Cokleisli w a b
forall a b. (a -> b) -> a -> b
$ a -> b
forall a b. IsomorphicTo a b => b -> a
to (a -> b) -> (w a -> a) -> w a -> b
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. w a -> a
forall (w :: * -> *) a. Comonad w => w a -> a
extract