Skip to content

Commit

Permalink
per Saizan, added cofree instance for Representable
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett committed Nov 7, 2011
1 parent 206e74a commit b99ad12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Data/Functor/Representable.hs
Expand Up @@ -48,6 +48,7 @@ module Data.Functor.Representable

import Control.Applicative
import Control.Comonad.Trans.Traced
import Control.Comonad.Cofree
import Control.Monad.Trans.Identity
import Control.Monad.Reader
import Data.Distributive
Expand All @@ -57,6 +58,7 @@ import Data.Functor.Identity
import Data.Functor.Compose
import Data.Functor.Product
import Data.Lens.Common
import qualified Data.Sequence as Seq
import Data.Semigroup hiding (Product)
import Prelude hiding (lookup)

Expand All @@ -77,7 +79,7 @@ class (Indexable f, Distributive f, Keyed f, Apply f, Applicative f, ZipWithKey
-- * Default definitions

fmapRep :: Representable f => (a -> b) -> f a -> f b
fmapRep f = tabulate . fmap f . index
fmapRep f = tabulate . fmap f . index

mapWithKeyRep :: Representable f => (Key f -> a -> b) -> f a -> f b
mapWithKeyRep f = tabulate . (<*>) f . index
Expand Down Expand Up @@ -145,3 +147,5 @@ instance Representable w => Representable (TracedT s w) where
instance (Representable f, Representable g) => Representable (Product f g) where
tabulate f = Pair (tabulate (f . Left)) (tabulate (f . Right))

instance Representable f => Representable (Cofree f) where
tabulate f = f Seq.empty :< tabulate (\k -> tabulate (f . (k Seq.<|)))
2 changes: 1 addition & 1 deletion representable-functors.cabal
@@ -1,6 +1,6 @@
name: representable-functors
category: Monads, Functors, Data Structures
version: 2.0.2
version: 2.1
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE
Expand Down

0 comments on commit b99ad12

Please sign in to comment.