Permalink
Browse files

haddock improvements and trailing whitespace removal

  • Loading branch information...
ekmett committed Feb 18, 2013
1 parent d712b9f commit a00f923c62fbcc6e8db17902063633a53de4dfb2
Showing with 17 additions and 15 deletions.
  1. +17 −15 src/Data/Functor/Contravariant/Adjunction.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-} {-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
module Data.Functor.Contravariant.Adjunction module Data.Functor.Contravariant.Adjunction
( Adjunction(..) ( Adjunction(..)
, corepAdjunction , corepAdjunction
, coindexAdjunction , coindexAdjunction
@@ -9,40 +9,42 @@ import Control.Monad.Instances ()
import Data.Functor.Contravariant import Data.Functor.Contravariant
import Data.Functor.Corepresentable import Data.Functor.Corepresentable
-- | An adjunction from Hask^op to Hask -- | An adjunction from @Hask^op@ to @Hask@
--
-- > Op (f a) b ~ Hask a (g b)
-- --
-- > rightAdjunct unit = id -- @'Op' (f a) b ~ 'Hask' a (g b)@
-- > leftAdjunct counit = id
-- --
-- Any adjunction from Hask to Hask^op would indirectly -- @
-- permit unsafePerformIO, and therefore does not exist. -- 'rightAdjunct' 'unit' = 'id'
-- 'leftAdjunct' 'counit' = 'id'
-- @
--
-- Any adjunction from @Hask@ to @Hask^op@ would indirectly
-- permit @unsafePerformIO@, and therefore does not exist.
class (Contravariant f, Corepresentable g) => Adjunction f g | f -> g, g -> f where class (Contravariant f, Corepresentable g) => Adjunction f g | f -> g, g -> f where
unit :: a -> g (f a) -- monad in Hask unit :: a -> g (f a) -- monad in Hask
counit :: a -> f (g a) -- comonad in Hask^op counit :: a -> f (g a) -- comonad in Hask^op
leftAdjunct :: (b -> f a) -> a -> g b leftAdjunct :: (b -> f a) -> a -> g b
rightAdjunct :: (a -> g b) -> b -> f a rightAdjunct :: (a -> g b) -> b -> f a
unit = leftAdjunct id unit = leftAdjunct id
counit = rightAdjunct id counit = rightAdjunct id
leftAdjunct f = contramap f . unit leftAdjunct f = contramap f . unit
rightAdjunct f = contramap f . counit rightAdjunct f = contramap f . counit
-- | This adjunction gives rise to the Cont monad -- | This 'Adjunction' gives rise to the @Cont@ 'Monad'
instance Adjunction (Op r) (Op r) where instance Adjunction (Op r) (Op r) where
unit a = Op (\k -> getOp k a) unit a = Op (\k -> getOp k a)
counit = unit counit = unit
-- | This gives rise to the Cont Bool monad -- | This gives rise to the @Cont Bool@ 'Monad'
instance Adjunction Predicate Predicate where instance Adjunction Predicate Predicate where
unit a = Predicate (\k -> getPredicate k a) unit a = Predicate (\k -> getPredicate k a)
counit = unit counit = unit
-- | Represent a contravariant functor that has a left adjoint -- | Represent a 'Contravariant' functor that has a left adjoint
corepAdjunction :: Adjunction f g => (a -> f ()) -> g a corepAdjunction :: Adjunction f g => (a -> f ()) -> g a
corepAdjunction = flip leftAdjunct () corepAdjunction = flip leftAdjunct ()
coindexAdjunction :: Adjunction f g => g a -> a -> f () coindexAdjunction :: Adjunction f g => g a -> a -> f ()
coindexAdjunction = rightAdjunct . const coindexAdjunction = rightAdjunct . const

0 comments on commit a00f923

Please sign in to comment.