packages feed

yaya 0.1.0.0 → 0.2.0.0

raw patch · 6 files changed

+79/−25 lines, 6 filesdep ~yayadep ~yaya-hedgehogPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: yaya, yaya-hedgehog

API changes (from Hackage documentation)

- Yaya.Fold: class DFunctor d
- Yaya.Fold: class HFunctor h
- Yaya.Fold: cursiveIso :: Steppable t f => BialgebraIso f t
- Yaya.Fold: dmap :: DFunctor d => (forall a. f a -> g a) -> d f -> d g
- Yaya.Fold: hmap :: HFunctor h => (forall a. f a -> g a) -> h f a -> h g a
+ Yaya.Fold: instance Yaya.Functor.DFunctor Yaya.Fold.Mu
+ Yaya.Fold: instance Yaya.Functor.DFunctor Yaya.Fold.Nu
+ Yaya.Fold: steppableIso :: Steppable t f => BialgebraIso f t
+ Yaya.Functor: class DFunctor (d :: (* -> *) -> *)
+ Yaya.Functor: class HFunctor (h :: (* -> *) -> * -> *)
+ Yaya.Functor: dmap :: DFunctor d => (forall a. f a -> g a) -> d f -> d g
+ Yaya.Functor: firstMap :: (DFunctor d, Bifunctor f) => (a -> b) -> d (f a) -> d (f b)
+ Yaya.Functor: hmap :: HFunctor h => (forall a. f a -> g a) -> h f a -> h g a

Files

+ CHANGELOG.md view
@@ -0,0 +1,18 @@+# Changelog+All notable changes to this project will be documented in this file.++The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),+and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/).++## 0.2.0.0 – 2019–01–08+### Added+- `DFunctor` instances for `Mu` and `Nu`+- lower bounds on internal yaya dependencies++### Changed+- moved `DFunctor` and `HFunctor` to a new `Yaya.Functor` module+- renamed `cursiveIso` to `steppableIso`++## 0.1.0.0 – 2019–01–04+### Added+- everything (this is the initial release)
src/Yaya/Fold.hs view
@@ -24,6 +24,7 @@ import Numeric.Natural  import Yaya.Fold.Common+import Yaya.Functor import Yaya.Pattern  type Algebra f a = f a -> a@@ -79,7 +80,6 @@ -- | A fixed-point operator for inductive / finite data structures. data Mu f = Mu (forall a. Algebra f a -> a) - instance Functor f => Projectable (Mu f) f where   project = lambek @@ -89,6 +89,9 @@ instance Recursive (Mu f) f where   cata φ (Mu f) = f φ +instance DFunctor Mu where+ dmap f (Mu fold) = Mu (\φ -> fold (φ . f))+ instance Show1 f => Show (Mu f) where   showsPrec = recursiveShowsPrec @@ -108,6 +111,9 @@ instance Corecursive (Nu f) f where   ana = Nu +instance DFunctor Nu where+  dmap f (Nu φ a) = Nu (f . φ) a+ instance Projectable [a] (XNor a) where   project []      = Neither   project (h : t) = Both h t@@ -309,6 +315,11 @@ ignoringAttribute :: Algebra f a -> Algebra (EnvT b f) a ignoringAttribute φ = φ . lowerEnvT +-- | It is somewhat common to have a natural transformation that looks like+--  `η :: forall a. f a -> Free g a`. This maps naturally to a `GCoalgebra` (to+--   pass to `apo`) with `η . project`, but the desired `Algebra` is more likely+--   to be `cata unFree . η` than `embed . η`. See yaya-streams for some+--   examples of this. unFree :: Steppable t f => Algebra (FreeF f t) t unFree = \case   Pure t  -> t@@ -317,7 +328,7 @@ -- preservingAttribute :: (forall a. f a -> g a) -> EnvT a f b -> EnvT a g b -- preservingAttribute = cohoist --- instances for non-recursive types+-- * instances for non-recursive types  constEmbed :: Algebra (Const a) a constEmbed = getConst@@ -355,30 +366,14 @@ instance Corecursive (Maybe a) (Const (Maybe a)) where   ana = constAna --- | An endofunctor in the category of endofunctors.-class HFunctor h where-  hmap :: (forall a. f a -> g a) -> h f a -> h g a----- | A functor from the category of endofunctors to *Hask*.-class DFunctor d where-  dmap :: (forall a. f a -> g a) -> d f -> d g---- instance DFunctor Mu where---   dmap f = cata (embed . f)---- instance DFunctor Fix where---   dmap f = ana (f . project)---- instance DFunctor Nu where---   dmap f = ana (f . project)+-- * Optics  type BialgebraIso f a = Iso' (f a) a type AlgebraPrism f a = Prism' (f a) a type CoalgebraPrism f a = Prism' a (f a) -cursiveIso :: Steppable t f => BialgebraIso f t-cursiveIso = iso embed project+steppableIso :: Steppable t f => BialgebraIso f t+steppableIso = iso embed project  birecursiveIso   :: (Recursive t f, Corecursive t f)
src/Yaya/Fold/Common.hs view
@@ -36,6 +36,19 @@   liftEq (==) (void f1) (void f2)   && and (zipWith fn (toList f1) (toList f2)) +-- -- | What we want here is a way we can get a+-- --  `corecursiveEq :: t -> t -> Partial Bool`, so we can define (unsafe) `Eq`+-- --   instances with `eq = runToEnd corecursiveEq`.+-- coequal :: (Functor f, Foldable f, Eq1 f) => t -> t -> Either Bool [(t, t)]+-- coequal a b =+--   let fa = project a+--       fb = project b+--   in if liftEq (==) (void fa) (void fb)+--      then case zip (toList fa) (toList fb) of+--             [] -> Left True+--             ps -> Right ps+--      else Left False+ -- TODO: Redefine this using `Natural` -- | When folded, returns the height of the data structure. height :: Foldable f => f Integer -> Integer
+ src/Yaya/Functor.hs view
@@ -0,0 +1,22 @@+-- | This should probably be a separate library, but it provides a number of+--   functor type classes between various categories.+module Yaya.Functor where++import Data.Bifunctor++-- | A functor from the category of endofunctors to *Hask*. The `D` is meant to+--   be a mnemonic for “down”, as we’re “lowering” from endofunctors to types.+class DFunctor (d :: (* -> *) -> *) where+  dmap :: (forall a. f a -> g a) -> d f -> d g++-- | This isn’t a Functor instance because of the position of the `a`, but you+--   can use it like:+--   > newtype List a = List (Mu (XNor a))+--   > instance Functor List where+--   >   map f (List mu) = List (firstMap f mu)+firstMap :: (DFunctor d, Bifunctor f) => (a -> b) -> d (f a) -> d (f b)+firstMap f = dmap (first f)++-- | An endofunctor in the category of endofunctors.+class HFunctor (h :: (* -> *) -> * -> *) where+  hmap :: (forall a. f a -> g a) -> h f a -> h g a
test/Test/Fold.hs view
@@ -21,5 +21,9 @@ -- prop_muCataCompose = --   property $ law_cataCompose size id =<< forAll genMuExpr +-- prop_nuAnaCancel :: Property+-- prop_nuAnaCancel =+--   property $ law_anaCancel size =<< forAll (genExpr (Gen.sized genNuExpr))+ tests :: IO Bool tests = checkParallel $$(discover)
yaya.cabal view
@@ -1,5 +1,5 @@ name:                yaya-version:             0.1.0.0+version:             0.2.0.0 synopsis:            Total recursion schemes. description:         Recursion schemes allow you to separate recursion from your                      business logic – making your own operations simpler, more@@ -15,7 +15,8 @@ license-file:        LICENSE category:            Recursion build-type:          Simple-extra-source-files:  README.md+extra-source-files:  CHANGELOG.md+                   , README.md cabal-version:       >=1.10  library@@ -24,6 +25,7 @@                      , Yaya.Fold                      , Yaya.Fold.Common                      , Yaya.Fold.Native+                     , Yaya.Functor                      , Yaya.Retrofit                      , Yaya.Applied                      , Yaya.Zoo@@ -64,8 +66,8 @@   build-depends:       base                      , deriving-compat                      , hedgehog-                     , yaya-                     , yaya-hedgehog+                     , yaya >= 0.1.0+                     , yaya-hedgehog >= 0.1.0   ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall   default-language:    Haskell2010