packages feed

representable-functors 3.1 → 3.2.0.1

raw patch · 4 files changed

+28/−4 lines, 4 filesdep ~arraydep ~comonad-transformersdep ~comonads-fd

Dependency ranges changed: array, comonad-transformers, comonads-fd, contravariant, distributive, free, keys, semigroupoids, semigroups

Files

CHANGELOG.markdown view
@@ -1,3 +1,11 @@+3.2.0.1+-------+* Fixed issue [#1](https://github.com/ekmett/representable-functors/pull/1). Did `RULES` parsing change with GHC 7.6.3?++3.2+---+* Added Day Convolution+ 3.1 --- * Required Distributive as a superclass
representable-functors.cabal view
@@ -1,6 +1,6 @@ name:          representable-functors category:      Monads, Functors, Data Structures-version:       3.1+version:       3.2.0.1 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -46,7 +46,7 @@     comonad-transformers >= 3,     comonads-fd          >= 3,     containers           >= 0.3 && < 0.6,-    contravariant        >= 0.2.0.1,+    contravariant        >= 0.4.1,     distributive         >= 0.2.2,     free                 >= 3,     keys                 >= 3,
src/Data/Functor/Contravariant/Representable.hs view
@@ -29,6 +29,7 @@  import Control.Monad.Reader import Data.Functor.Contravariant+import Data.Functor.Contravariant.Day import Data.Functor.Product import Data.Functor.Coproduct import Prelude hiding (lookup)@@ -39,14 +40,30 @@ class Contravariant f => Valued f where   contramapWithValue :: (b -> Either a (Value f)) -> f a -> f b +instance (Valued f, Valued g) => Valued (Day f g) where+  contramapWithValue d2eafg (Day fb gc abc) = Day (contramapWithValue id fb) (contramapWithValue id gc) $ \d -> case d2eafg d of+    Left a -> case abc a of+      (b, c) -> (Left b, Left c)+    Right (vf, vg) -> (Right vf, Right vg)+ -- | Dual to 'Indexed'. class Coindexed f where   coindex :: f a -> a -> Value f +type instance Value (Day f g) = (Value f, Value g)++instance (Coindexed f, Coindexed g) => Coindexed (Day f g) where+  coindex (Day fb gc abc) a = case abc a of+    (b, c) -> (coindex fb b, coindex gc c)+ -- | A 'Contravariant' functor @f@ is 'Representable' if 'contrarep' and 'coindex' witness an isomorphism to @(_ -> Value f)@. class (Coindexed f, Valued f) => Representable f where   -- | > contramap f (contrarep g) = contrarep (g . f)   contrarep :: (a -> Value f) -> f a++instance (Representable f, Representable g) => Representable (Day f g) where+  contrarep a2fg = Day (contrarep fst) (contrarep snd) $ \a -> let b = a2fg a in (b,b)+  {-# INLINE contrarep #-}  {-# RULES "contrarep/coindex" forall t. contrarep (coindex t) = t
src/Data/Functor/Representable.hs view
@@ -83,8 +83,7 @@   tabulate :: (Key f -> a) -> f a  {-# RULES-"tabulate/index" forall t. tabulate (index t) = t- #-}+"tabulate/index" forall t. tabulate (index t) = t #-}  -- * Default definitions