adjunctions 4.0.1 → 4.0.2
raw patch · 3 files changed
+44/−10 lines, 3 files
Files
- CHANGELOG.markdown +7/−0
- adjunctions.cabal +1/−1
- src/Data/Functor/Rep.hs +36/−9
CHANGELOG.markdown view
@@ -1,3 +1,10 @@+4.0.2+-----+* Added `mfixRep` to make it easier to define representable `MonadFix` instances.+* Added `mzipRep` and `mzipWithRep` to make it easier to define representable `MonadZip` instances.+* Added `duplicateRepBy`, `extendRepBy` and `extractRepBy` to make it easier to pick your own `Monoid`.+* Minor documentation fixes.+ 4.0.1 ----- * Increased lower bound on `contravariant` to match the actual requirement.
adjunctions.cabal view
@@ -1,6 +1,6 @@ name: adjunctions category: Data Structures, Adjunctions-version: 4.0.1+version: 4.0.2 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE
src/Data/Functor/Rep.hs view
@@ -37,6 +37,11 @@ , liftR3 -- ** Bind/Monad , bindRep+ -- ** MonadFix+ , mfixRep+ -- ** MonadZip+ , mzipRep+ , mzipWithRep -- ** MonadReader , askRep , localRep@@ -47,6 +52,10 @@ , duplicateRep , extendRep , extractRep+ -- ** Comonad, with user-specified monoid+ , duplicateRepBy+ , extendRepBy+ , extractRepBy ) where import Control.Applicative@@ -77,9 +86,9 @@ -- Every 'Representable' 'Functor' from Hask to Hask is a right adjoint. -- -- @--- 'tabulate' . 'index' ≡ id--- 'index' . 'tabulate' ≡ id--- 'tabulate' . 'return' f ≡ 'return' f+-- 'tabulate' . 'index' ≡ id+-- 'index' . 'tabulate' ≡ id+-- 'tabulate' . 'return' ≡ 'return' -- @ class Distributive f => Representable f where@@ -105,6 +114,15 @@ bindRep :: Representable f => f a -> (a -> f b) -> f b bindRep m f = tabulate $ \a -> index (f (index m a)) a +mfixRep :: Representable f => (a -> f a) -> f a+mfixRep = tabulate . mfix . fmap index++mzipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f c+mzipWithRep f as bs = tabulate $ \k -> f (index as k) (index bs k)++mzipRep :: Representable f => f a -> f b -> f (a, b)+mzipRep as bs = tabulate $ \k -> (index as k, index bs k)+ askRep :: Representable f => f (Rep f) askRep = tabulate id @@ -117,27 +135,36 @@ distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a) distributeRep wf = tabulate (\k -> fmap (`index` k) wf) +duplicateRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> f a -> f (f a)+duplicateRepBy plus w = tabulate (\m -> tabulate (index w . plus m))++extendRepBy :: Representable f => (Rep f -> Rep f -> Rep f) -> (f a -> b) -> f a -> f b+extendRepBy plus f w = tabulate (\m -> f (tabulate (index w . plus m)))++extractRepBy :: Representable f => (Rep f) -> f a -> a+extractRepBy = flip index+ duplicatedRep :: (Representable f, Semigroup (Rep f)) => f a -> f (f a)-duplicatedRep w = tabulate (\m -> tabulate (index w . (<>) m))+duplicatedRep = duplicateRepBy (<>) extendedRep :: (Representable f, Semigroup (Rep f)) => (f a -> b) -> f a -> f b-extendedRep f w = tabulate (\m -> f (tabulate (index w . (<>) m)))+extendedRep = extendRepBy (<>) duplicateRep :: (Representable f, Monoid (Rep f)) => f a -> f (f a)-duplicateRep w = tabulate (\m -> tabulate (index w . mappend m))+duplicateRep = duplicateRepBy mappend extendRep :: (Representable f, Monoid (Rep f)) => (f a -> b) -> f a -> f b-extendRep f w = tabulate (\m -> f (tabulate (index w . mappend m)))+extendRep = extendRepBy mappend extractRep :: (Representable f, Monoid (Rep f)) => f a -> a-extractRep fa = index fa mempty+extractRep = extractRepBy mempty -- * Instances instance Representable Proxy where type Rep Proxy = Void index Proxy = absurd- tabulate f = Proxy+ tabulate _ = Proxy instance Representable Identity where type Rep Identity = ()