packages feed

hs-functors 0.1.4.0 → 0.1.5.0

raw patch · 6 files changed

+157/−9 lines, 6 filesdep +taggeddep ~transformerssetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies added: tagged

Dependency ranges changed: transformers

API changes (from Hackage documentation)

+ Data.Fix: cotraverseFix :: (Cotraversable f, Comonad ɯ) => (forall a. ɯ (f a) -> g a) -> ɯ (Fix f) -> Fix g
+ Data.Fix: traverseFix :: (Traversable f, Monad m) => (forall a. f a -> m (g a)) -> Fix f -> m (Fix g)
+ Data.FnList: Done :: c -> FnList a b c
+ Data.FnList: More :: a -> FnList a b (b -> c) -> FnList a b c
+ Data.FnList: answer :: (a -> b) -> FnList a b c -> c
+ Data.FnList: arguments :: FnList a b c -> [a]
+ Data.FnList: argumentsL :: Applicative p => (a -> p a') -> FnList a b c -> p (FnList a' b c)
+ Data.FnList: data FnList a b c
+ Data.FnList: holes :: FnList a b c -> [(a, a -> FnList a b c)]
+ Data.FnList: instance Data.Foldable.Foldable (Data.FnList.FnList a a)
+ Data.FnList: instance Data.Profunctor.Profunctor (Data.FnList.FnList a)
+ Data.FnList: instance GHC.Base.Applicative (Data.FnList.FnList a b)
+ Data.FnList: instance GHC.Base.Functor (Data.FnList.FnList a b)
+ Data.FnList: merge :: Ord a => FnList a b (c -> d) -> FnList a b c -> FnList a b d
+ Data.FnList: mergeBy :: forall a b c d. (a -> a -> Ordering) -> FnList a b (c -> d) -> FnList a b c -> FnList a b d
+ Data.FnList: permutations :: FnList a b c -> NonEmpty (FnList a b c)
+ Data.FnList: singleton :: a -> FnList a b b
+ Data.FnList: untraverse :: Applicative f => (a -> f b) -> FnList a b c -> f c
+ Data.FnList: zip :: FnList a₁ a₁ c₁ -> FnList a₂ a₂ c₂ -> FnList (a₁, a₂) (a₁, a₂) (c₁, c₂)
+ Data.Profunctor: class Profunctor p => Colift f p
+ Data.Profunctor: class Profunctor p => Lift f p
+ Data.Profunctor: colift :: Colift f p => p (f a) (f b) -> p a b
+ Data.Profunctor: instance (Data.Cotraversable.Cotraversable f, GHC.Base.Functor ɯ) => Data.Profunctor.Lift f (Control.Comonad.Cokleisli ɯ)
+ Data.Profunctor: instance (Data.Profunctor.Colift f p, GHC.Base.Functor g) => Data.Profunctor.Colift f (Data.Bifunctor.Tannen.Tannen g p)
+ Data.Profunctor: instance (Data.Profunctor.Lift f p, GHC.Base.Functor g) => Data.Profunctor.Lift f (Data.Bifunctor.Tannen.Tannen g p)
+ Data.Profunctor: instance (Data.Profunctor.Lift φ p, GHC.Base.Functor f, GHC.Base.Applicative g, Data.Traversable.Traversable φ, Data.Cotraversable.Cotraversable φ) => Data.Profunctor.Lift φ (Data.Bifunctor.Biff.Biff p f g)
+ Data.Profunctor: instance (Data.Profunctor.Profunctor p, GHC.Base.Functor f, GHC.Base.Functor g) => Data.Profunctor.Profunctor (Data.Bifunctor.Biff.Biff p f g)
+ Data.Profunctor: instance (Data.Traversable.Traversable f, GHC.Base.Applicative p) => Data.Profunctor.Lift f (Control.Arrow.Kleisli p)
+ Data.Profunctor: instance (GHC.Base.Functor f, Data.Cotraversable.Cotraversable g, Data.Profunctor.Lift ((->) a) p) => Data.Profunctor.Lift ((->) a) (Data.Bifunctor.Biff.Biff p f g)
+ Data.Profunctor: instance (GHC.Base.Functor f, Data.Profunctor.Profunctor p) => Data.Profunctor.Profunctor (Data.Bifunctor.Tannen.Tannen f p)
+ Data.Profunctor: instance Control.Monad.Fix.MonadFix m => Data.Profunctor.Colift ((,) c) (Control.Arrow.Kleisli m)
+ Data.Profunctor: instance Data.Cotraversable.Cotraversable m => Data.Profunctor.Lift ((->) a) (Control.Arrow.Kleisli m)
+ Data.Profunctor: instance Data.Profunctor.Colift ((,) c) (->)
+ Data.Profunctor: instance Data.Profunctor.Colift (Data.Either.Either c) (->)
+ Data.Profunctor: instance Data.Profunctor.Profunctor Data.Tagged.Tagged
+ Data.Profunctor: instance GHC.Base.Applicative f => Data.Profunctor.Lift f Data.Tagged.Tagged
+ Data.Profunctor: instance GHC.Base.Functor f => Data.Profunctor.Colift (Data.Either.Either c) (Control.Comonad.Cokleisli f)
+ Data.Profunctor: instance GHC.Base.Functor f => Data.Profunctor.Lift ((->) a) (Control.Comonad.Cokleisli f)
+ Data.Profunctor: instance GHC.Base.Functor f => Data.Profunctor.Lift f (->)
+ Data.Profunctor: instance GHC.Base.Functor ɯ => Data.Profunctor.Colift ((,) c) (Control.Comonad.Cokleisli ɯ)
+ Data.Profunctor: instance GHC.Base.Monad m => Data.Profunctor.Colift (Data.Either.Either c) (Control.Arrow.Kleisli m)
+ Data.Profunctor: lift :: Lift f p => p a b -> p (f a) (f b)

Files

Control/Comonad/Cofree.hs view
@@ -8,7 +8,6 @@ import Control.Monad import Data.Cotraversable import Data.Functor.Classes-import Data.Profunctor import Data.Semigroup ((<>)) import Text.Read (Read (..)) @@ -58,7 +57,7 @@ lower (Cofree _ t) = copure <$> t  coiter :: Functor f => (a -> f a) -> a -> Cofree f a-coiter f = unfold (id &&& f)+coiter f = unfold ((,) <*> f)  coiterW :: (Comonad ɯ, Functor f) => (ɯ a -> f (ɯ a)) -> ɯ a -> Cofree f a coiterW f ɯ = copure ɯ `Cofree` (coiterW f <$> f ɯ)
Data/Fix.hs view
@@ -18,6 +18,12 @@ mapFix :: Functor f => (∀ a . f a -> g a) -> Fix f -> Fix g mapFix f = Fix . f . fmap (mapFix f) . unFix +traverseFix :: (Traversable f, Monad m) => (∀ a . f a -> m (g a)) -> Fix f -> m (Fix g)+traverseFix f = fmap Fix . f <=< traverse (traverseFix f) . unFix++cotraverseFix :: (Cotraversable f, Comonad ɯ) => (∀ a . ɯ (f a) → g a) -> ɯ (Fix f) -> Fix g+cotraverseFix f = Fix . f =<= cotraverse (cotraverseFix f) . fmap unFix+ cata :: Functor f => (f a -> a) -> Fix f -> a cata f = f . fmap (cata f) . unFix 
+ Data/FnList.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Data.FnList where++import Prelude hiding (zip, tail)+import Control.Applicative+import Data.List.NonEmpty (NonEmpty (..), tail)+import Data.Profunctor++data FnList a b c = Done c | More a (FnList a b (b -> c))+  deriving (Functor)++instance Profunctor (FnList a) where+    dimap _ g (Done c) = Done (g c)+    dimap f g (More a z) = More a $ dimap f (dimap f g) z++arguments :: FnList a b c -> [a]+arguments (Done _) = []+arguments (More a z) = a : arguments z++answer :: (a -> b) -> FnList a b c -> c+answer _ (Done c) = c+answer f (More a z) = answer f z (f a)++instance Foldable (FnList a a) where foldMap φ = φ . answer id++instance Applicative (FnList a b) where+    pure = Done+    Done b <*> c = b <$> c+    More a z <*> c = More a (flip <$> z <*> c)++zip :: FnList a₁ a₁ c₁ -> FnList a₂ a₂ c₂ -> FnList (a₁, a₂) (a₁, a₂) (c₁, c₂)+zip (Done b₁) y = Done (b₁, answer id y)+zip x (Done b₂) = Done (answer id x, b₂)+zip (More a₁ x) (More a₂ y) = More (a₁, a₂) (uncurry (***) <$> zip x y)++argumentsL :: Applicative p => (a -> p a') -> FnList a b c -> p (FnList a' b c)+argumentsL _ (Done c) = pure (Done c)+argumentsL f (More a z) = More <$> f a <*> argumentsL f z++singleton :: a -> FnList a b b+singleton = More `flip` Done id++untraverse :: Applicative f => (a -> f b) -> FnList a b c -> f c+untraverse _ (Done c) = pure c+untraverse f (More a z) = f a <**> untraverse f z++permutations :: FnList a b c -> NonEmpty (FnList a b c)+permutations = (:|) <*> tail . go where+    go (Done c) = pure (Done c)+    go (More a z) = permutations z >>= \ z' ->+        More a z' :| fmap (\ (b, f) -> More b (f a)) (holes z')++holes :: FnList a b c -> [(a, a -> FnList a b c)]+holes (Done _) = []+holes (More a z) = (a, flip More z) : (fmap . fmap . fmap) (More a) (holes z)++merge :: Ord a => FnList a b (c -> d) -> FnList a b c -> FnList a b d+merge = mergeBy compare++mergeBy :: ∀ a b c d . (a -> a -> Ordering) -> FnList a b (c -> d) -> FnList a b c -> FnList a b d+mergeBy cmp = go where+    go :: ∀ b c d . FnList a b (c -> d) -> FnList a b c -> FnList a b d+    go (Done b) c = b <$> c+    go b (Done c) = ($ c) <$> b+    go (More a x) (More b y) = case cmp a b of+        GT -> More b (go ((.) <$> More a x) y)+        _  -> More a (go (flip <$> x) (More b y))
Data/Profunctor.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE DefaultSignatures #-}  module Data.Profunctor where@@ -11,8 +11,11 @@ import Control.Comonad import Control.Monad import Control.Monad.Fix+import Data.Bifunctor.Biff import Data.Bifunctor.Braided+import Data.Bifunctor.Tannen import Data.Cotraversable+import Data.Tagged  class Profunctor p where     dimap :: (a -> b) -> (c -> d) -> p b c -> p a d@@ -47,6 +50,74 @@ instance Functor f => Profunctor (Cokleisli f) where     dimap f g (Cokleisli a) = Cokleisli (g . a . fmap f) +instance (Profunctor p, Functor f, Functor g) => Profunctor (Biff p f g) where+    dimap f g = Biff . dimap (fmap f) (fmap g) . unBiff++instance (Functor f, Profunctor p) => Profunctor (Tannen f p) where+    dimap f g = Tannen . fmap (dimap f g) . unTannen++instance Profunctor Tagged where+    dimap _ g = Tagged . g . unTagged+++class Profunctor p => Lift f p where+    lift :: p a b -> p (f a) (f b)++instance Functor f => Lift f (->) where lift = fmap++instance (Traversable f, Applicative p) => Lift f (Kleisli p) where+    lift = Kleisli . traverse . runKleisli++instance (Cotraversable f, Functor ɯ) => Lift f (Cokleisli ɯ) where+    lift = Cokleisli . cotraverse . runCokleisli++instance (Lift φ p, Functor f, Applicative g, Traversable φ, Cotraversable φ) => Lift φ (Biff p f g) where+    lift = Biff . dimap cosequence sequenceA . lift . unBiff++instance (Cotraversable m) => Lift ((->) a) (Kleisli m) where+    lift (Kleisli afb) = Kleisli $ \ xa -> cosequence $ afb . xa++instance (Functor f) => Lift ((->) a) (Cokleisli f) where+    lift (Cokleisli f) = Cokleisli $ \ fs a -> f $ ($ a) <$> fs++instance (Functor f, Cotraversable g, Lift ((->) a) p) => Lift ((->) a) (Biff p f g) where+    lift = Biff . dimap (flip $ fmap . flip id) cosequence . lift . unBiff++instance (Lift f p, Functor g) => Lift f (Tannen g p) where+    lift = Tannen . fmap lift . unTannen++instance Applicative f => Lift f Tagged where+    lift = Tagged . pure . unTagged+++class Profunctor p => Colift f p where+    colift :: p (f a) (f b) -> p a b++instance Colift ((,) c) (->) where+    colift f a = let (c, b) = f (c, a) in b++instance MonadFix m => Colift ((,) c) (Kleisli m) where+    colift (Kleisli f) = Kleisli $ \ a -> snd <$> mfix (f . flip (,) a . fst)++instance Functor ɯ => Colift ((,) c) (Cokleisli ɯ) where+    colift (Cokleisli f) = Cokleisli $ \ a -> snd $ fix (f . flip fmap a . (,) . fst)++instance Colift (Either c) (->) where+    colift f = let go = either (go . f . Left) id in go . f . Right++instance Monad m => Colift (Either c) (Kleisli m) where+    colift (Kleisli f) = let go = either (go <=< f . Left) pure in Kleisli (go <=< f . Right)++instance Functor f => Colift (Either c) (Cokleisli f) where+    colift (Cokleisli f) = Cokleisli (go . fmap Right)+      where go ɯ = case f ɯ of Left  b -> go (Left  b <$ ɯ)+                               Right c -> c++instance (Colift f p, Functor g) => Colift f (Tannen g p) where+    colift = Tannen . fmap colift . unTannen+++{-# DEPRECATED #-} class Profunctor p => Strong f p where     strong :: p a₁ b₁ -> p a₂ b₂ -> p (f a₁ a₂) (f b₁ b₂) @@ -85,6 +156,7 @@         (\ a -> Right . g . (a <$)) ^>> Cokleisli (copure <*> void)  +{-# DEPRECATED #-} class Profunctor p => Costrong f p where     costrongL :: p (f a c) (f b c) -> p a b     costrongR :: p (f a b) (f a c) -> p b c@@ -112,6 +184,8 @@       where go ɯ = case f ɯ of Left  b -> b                                Right c -> go (Right c <$ ɯ) ++{-# DEPRECATED #-} class Profunctor p => Closed f p where     closed :: p a b -> p (f a) (f b) 
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
hs-functors.cabal view
@@ -1,5 +1,5 @@ name:                hs-functors-version:             0.1.4.0+version:             0.1.5.0 synopsis:            Functors from products of Haskell and its dual to Haskell -- description:          license:             BSD3@@ -10,8 +10,8 @@ category:            Math build-type:          Simple cabal-version:       >=1.10-tested-with:         GHC ==8.2.2-                   , GHC ==8.4.2+tested-with:         GHC ==8.4.3+                   , GHC ==8.6.4  library   exposed-modules:     Control.Comonad@@ -28,13 +28,15 @@                      , Data.Bifunctor.Tannen                      , Data.Cotraversable                      , Data.Fix+                     , Data.FnList                      , Data.Functor.Contravariant                      , Data.Functor.Join                      , Data.Profunctor   -- other-modules:          -- other-extensions:       build-depends:       base >=4.9 && <5-                     , transformers >=0.4.2 && <0.6+                     , tagged >=0.8.6 && <0.9+                     , transformers >=0.5.3 && <0.6   -- hs-source-dirs:         default-language:    Haskell2010   default-extensions:  LambdaCase@@ -42,6 +44,7 @@                      , TypeOperators                      , PolyKinds                      , RankNTypes+                     , FlexibleContexts, FlexibleInstances                      , StandaloneDeriving                      , GeneralizedNewtypeDeriving                      , DeriveFunctor, DeriveFoldable, DeriveTraversable