Skip to content

Commit

Permalink
(co)representable profunctor composition
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett committed Jul 25, 2011
1 parent cd0071f commit 76c48aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Data/Profunctor/Corepresentable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ module Data.Profunctor.Corepresentable
( CorepresentableProfunctor(..)
) where

import Data.Functor
import Data.Functor.Identity
import Data.Profunctor
import Control.Arrow
import Data.Functor.Identity
import qualified Data.Profunctor.Composition as Profunctor
import qualified Data.Functor.Compose as Functor

class Functor (Corep k) => CorepresentableProfunctor k where
type Corep k :: * -> *
Expand All @@ -27,3 +30,8 @@ instance Functor f => CorepresentableProfunctor (UpStar f) where
type Corep (UpStar f) = f
cotabulatePro = UpStar
coindexPro = runUpStar

instance (CorepresentableProfunctor c, CorepresentableProfunctor d) => CorepresentableProfunctor (Profunctor.Compose c d) where
type Corep (Profunctor.Compose c d) = Functor.Compose (Corep c) (Corep d)
cotabulatePro f = Profunctor.Compose (cotabulatePro (Functor.getCompose . f)) (cotabulatePro id)
coindexPro (Profunctor.Compose f g) d = Functor.Compose $ coindexPro g <$> coindexPro f d
10 changes: 9 additions & 1 deletion Data/Profunctor/Representable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module Data.Profunctor.Representable
( RepresentableProfunctor(..)
) where

import Data.Functor
import Data.Functor.Identity
import qualified Data.Functor.Compose as Functor
import Data.Profunctor
import qualified Data.Profunctor.Composition as Profunctor
import Control.Comonad
import Data.Functor.Identity

class Functor (Rep k) => RepresentableProfunctor k where
type Rep k :: * -> *
Expand All @@ -26,3 +29,8 @@ instance Functor f => RepresentableProfunctor (DownStar f) where
type Rep (DownStar f) = f
tabulatePro = DownStar
indexPro = runDownStar

instance (RepresentableProfunctor f, RepresentableProfunctor g) => RepresentableProfunctor (Profunctor.Compose f g) where
type Rep (Profunctor.Compose f g) = Functor.Compose (Rep g) (Rep f)
tabulatePro f = Profunctor.Compose (tabulatePro id) (tabulatePro (f . Functor.Compose))
indexPro (Profunctor.Compose f g) (Functor.Compose d) = indexPro g $ indexPro f <$> d
3 changes: 2 additions & 1 deletion representable-profunctors.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: representable-profunctors
category: Control, Categories
version: 0.1.0.2
version: 0.2.0
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE
Expand All @@ -22,6 +22,7 @@ library
base >= 4 && < 5,
comonad >= 1.1 && < 1.2,
profunctors >= 0.1.1 && < 0.2,
profunctor-extras >= 0.2 && < 0.3,
transformers >= 0.2.2.0 && < 0.3

exposed-modules:
Expand Down

0 comments on commit 76c48aa

Please sign in to comment.