yaya-unsafe 0.1.0.0 → 0.1.1.0
raw patch · 6 files changed
+101/−68 lines, 6 filesdep ~yayadep ~yaya-hedgehogdep ~yaya-unsafe
Dependency ranges changed: yaya, yaya-hedgehog, yaya-unsafe
Files
- CHANGELOG.md +16/−0
- src/Yaya/Unsafe/Fold.hs +14/−14
- src/Yaya/Unsafe/Fold/Instances.hs +19/−19
- src/Yaya/Unsafe/Zoo.hs +32/−28
- test/Test/Fold.hs +13/−1
- yaya-unsafe.cabal +7/−6
+ CHANGELOG.md view
@@ -0,0 +1,16 @@+# 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.1.1.0 – 2019–01–08+### Added+- lower bounds on internal yaya dependencies++### Changed+- weakened constraints on a couple operations++## 0.1.0.0 – 2019–01–04+### Added+- everything (this is the initial release)
src/Yaya/Unsafe/Fold.hs view
@@ -64,39 +64,39 @@ fmap extract . hyloM (lowerAlgebraM w φ) (lowerCoalgebraM n ψ) . pure stream'- :: (Steppable t e, Steppable u f, Functor f)- => CoalgebraM Maybe f b- -> (b -> ((b -> b, t) -> u) -> e t -> u)+ :: (Projectable t f, Steppable u g, Functor g)+ => CoalgebraM Maybe g b+ -> (b -> ((b -> b, t) -> u) -> f t -> u) -> b -> t -> u stream' ψ f = go where go c x =- maybe (f c (uncurry go . ((&) c *** id)) $ project x)+ maybe (f c (uncurry go . ((&) c *** id)) (project x)) (embed . fmap (flip go x))- $ ψ c+ (ψ c) -- | Gibbons’ metamorphism. It lazily folds a (necessarily infinite) value, -- incrementally re-expanding that value into some new representation. streamAna- :: (Steppable t e, Steppable u f, Functor f)- => CoalgebraM Maybe f b- -> AlgebraM ((,) (b -> b)) e t+ :: (Projectable t f, Steppable u g, Functor g)+ => CoalgebraM Maybe g b+ -> AlgebraM ((,) (b -> b)) f t -> b -> t -> u-streamAna ψ φ = stream' ψ $ \c f -> f . φ+streamAna ψ φ = stream' ψ (\c f -> f . φ) -- | Another form of Gibbons’ metamorphism. This one can be applied to non- -- infinite inputs and takes an additional “flushing” coalgebra to be applied -- after all the input has been consumed. streamGApo- :: (Steppable t e, Steppable u f, Corecursive u f, Functor f)- => Coalgebra f b- -> CoalgebraM Maybe f b- -> (e t -> Maybe (b -> b, t))+ :: (Projectable t f, Steppable u g, Corecursive u g, Functor g)+ => Coalgebra g b+ -> CoalgebraM Maybe g b+ -> (f t -> Maybe (b -> b, t)) -> b -> t -> u-streamGApo ψ' ψ φ = stream' ψ $ \c f -> maybe (ana ψ' c) f . φ+streamGApo ψ' ψ φ = stream' ψ (\c f -> maybe (ana ψ' c) f . φ) corecursivePrism :: (Steppable t f, Recursive t f, Corecursive t f, Traversable f)
src/Yaya/Unsafe/Fold/Instances.hs view
@@ -9,22 +9,22 @@ -- to terminate. module Yaya.Unsafe.Fold.Instances where -import Control.Arrow-import Control.Comonad-import Control.Comonad.Cofree-import Control.Comonad.Env-import Control.Monad-import Control.Monad.Trans.Free-import Data.Functor.Classes-import Data.List.NonEmpty+import Control.Arrow+import Control.Comonad+import Control.Comonad.Cofree+import Control.Comonad.Env+import Control.Monad+import Control.Monad.Trans.Free+import Data.Functor.Classes+import Data.List.NonEmpty -import Yaya.Fold-import Yaya.Fold.Native-import Yaya.Pattern-import Yaya.Unsafe.Fold+import Yaya.Fold+import Yaya.Fold.Native+import Yaya.Pattern+import qualified Yaya.Unsafe.Fold as Unsafe instance Functor f => Recursive (Fix f) f where- cata = flip hylo project+ cata = flip Unsafe.hylo project instance (Functor f, Foldable f, Eq1 f) => Eq (Fix f) where (==) = recursiveEq@@ -33,10 +33,10 @@ showsPrec = recursiveShowsPrec instance Functor f => Corecursive (Mu f) f where- ana = hylo embed+ ana = Unsafe.hylo embed instance Functor f => Recursive (Nu f) f where- cata = flip hylo project+ cata = flip Unsafe.hylo project instance (Functor f, Foldable f, Eq1 f) => Eq (Nu f) where (==) = recursiveEq@@ -45,16 +45,16 @@ showsPrec = recursiveShowsPrec instance Recursive [a] (XNor a) where- cata = flip hylo project+ cata = flip Unsafe.hylo project instance Recursive (NonEmpty a) (AndMaybe a) where- cata = flip hylo project+ cata = flip Unsafe.hylo project instance Functor f => Recursive (Cofree f a) (EnvT a f) where- cata = flip hylo project+ cata = flip Unsafe.hylo project instance Functor f => Recursive (Free f a) (FreeF f a) where- cata = flip hylo project+ cata = flip Unsafe.hylo project -- TODO: If we can generalize this to an arbitrary 'Recursive t (FreeF h a)' -- then it would no longer be unsafe.
src/Yaya/Unsafe/Zoo.hs view
@@ -1,18 +1,18 @@ module Yaya.Unsafe.Zoo where -import Control.Arrow-import Control.Comonad.Cofree-import Control.Comonad.Env-import Control.Monad.Trans.Free-import Data.Functor.Compose-import Data.Functor.Identity-import Data.Bitraversable+import Control.Arrow+import Control.Comonad.Cofree+import Control.Comonad.Env+import Control.Monad.Trans.Free+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Bitraversable -import Yaya.Fold-import Yaya.Fold.Native-import Yaya.Pattern-import Yaya.Unsafe.Fold-import Yaya.Unsafe.Fold.Instances -- NB: extremely unsafe+import Yaya.Fold+import Yaya.Fold.Native+import Yaya.Pattern+import qualified Yaya.Unsafe.Fold as Unsafe+import qualified Yaya.Unsafe.Fold.Instances as Unsafe -- NB: extremely unsafe chrono :: Functor f@@ -20,28 +20,28 @@ -> GCoalgebra (Free f) f a -> a -> b-chrono = ghylo (distCofreeT id) (seqFreeT id)+chrono = Unsafe.ghylo (distCofreeT id) (Unsafe.seqFreeT id) codyna :: Functor f => Algebra f b -> GCoalgebra (Free f) f a -> a -> b-codyna φ = ghylo distIdentity (seqFreeT id) (φ . fmap runIdentity)+codyna φ = Unsafe.ghylo distIdentity (Unsafe.seqFreeT id) (φ . fmap runIdentity) -- | [Recursion Schemes for Dynamic Programming](https://www.researchgate.net/publication/221440162_Recursion_Schemes_for_Dynamic_Programming) dyna :: Functor f => GAlgebra (Cofree f) f b -> Coalgebra f a -> a -> b-dyna φ ψ = ghylo (distCofreeT id) seqIdentity φ (fmap Identity . ψ)+dyna φ ψ = Unsafe.ghylo (distCofreeT id) seqIdentity φ (fmap Identity . ψ) -- | Unlike most 'hylo's, 'elgot' composes an algebra and coalgebra in a way -- that allows information to move between them. The coalgebra can return, -- effectively, a pre-folded branch, short-circuiting parts of the process. elgot :: Functor f => Algebra f b -> ElgotCoalgebra (Either b) f a -> a -> b-elgot φ ψ = hylo ((id ||| φ) . getCompose) (Compose . ψ)+elgot φ ψ = Unsafe.hylo ((id ||| φ) . getCompose) (Compose . ψ) -- | The dual of 'elgot', 'coelgot' allows the _algebra_ to short-circuit in -- some cases – operating directly on a part of the seed. coelgot :: Functor f => ElgotAlgebra ((,) a) f b -> Coalgebra f a -> a -> b-coelgot φ ψ = hylo (φ . getCompose) (Compose . (id &&& ψ))+coelgot φ ψ = Unsafe.hylo (φ . getCompose) (Compose . (id &&& ψ)) futu :: (Corecursive t f, Functor f) => GCoalgebra (Free f) f a -> a -> t-futu = gana (seqFreeT id)+futu = gana (Unsafe.seqFreeT id) gprepro :: (Steppable t f, Recursive t f, Functor f, Comonad w)@@ -50,7 +50,8 @@ -> (forall a. f a -> f a) -> t -> a-gprepro k φ e = ghylo k seqIdentity φ (fmap (Identity . cata (embed . e)) . project)+gprepro k φ e =+ Unsafe.ghylo k seqIdentity φ (fmap (Identity . cata (embed . e)) . project) gpostpro :: (Steppable t f, Corecursive t f, Functor f, Monad m)@@ -59,7 +60,8 @@ -> GCoalgebra m f a -> a -> t-gpostpro k e = ghylo distIdentity k (embed . fmap (ana (e . project) . runIdentity))+gpostpro k e =+ Unsafe.ghylo distIdentity k (embed . fmap (ana (e . project) . runIdentity)) -- | The metamorphism definition from Gibbons’ paper. stream :: Coalgebra (XNor c) b -> (b -> a -> b) -> b -> [a] -> [c]@@ -74,13 +76,15 @@ -> b -> [a] -> [c]-fstream f g h = streamGApo h- (\b -> case f b of- Neither -> Nothing- other -> Just other)- (\case- Neither -> Nothing- Both a x' -> Just (flip g a, x'))+fstream f g h =+ Unsafe.streamGApo+ h+ (\b -> case f b of+ Neither -> Nothing+ other -> Just other)+ (\case+ Neither -> Nothing+ Both a x' -> Just (flip g a, x')) -- snoc :: [a] -> a -> [a] -- snoc x a = x ++ [a]@@ -99,7 +103,7 @@ => (a -> m b) -> t -> m u-cotraverse f = anaM (bitraverse f pure . project)+cotraverse f = Unsafe.anaM (bitraverse f pure . project) -- | Zygohistomorphic prepromorphism – everyone’s favorite recursion scheme joke. zygoHistoPrepro
test/Test/Fold.hs view
@@ -8,8 +8,14 @@ import Yaya.Fold.Common import Yaya.Hedgehog.Expr import Yaya.Hedgehog.Fold-import Yaya.Unsafe.Fold.Instances ()+import qualified Yaya.Unsafe.Fold.Instances () +-- | NB: Only in yaya-unsafe instead of yaya because the `Eq (Fix f)` instance+-- is needed.+prop_fixAnaRefl :: Property+prop_fixAnaRefl =+ property $ law_anaRefl =<< forAll (Gen.sized genFixExpr)+ prop_fixCataCancel :: Property prop_fixCataCancel = property $ law_cataCancel size =<< forAll (genExpr (Gen.sized genFixExpr))@@ -21,6 +27,12 @@ -- prop_fixCataCompose :: Property -- prop_fixCataCompose = -- property $ law_cataCompose size id =<< forAll (Gen.sized genFixExpr)++-- | NB: Only in yaya-unsafe instead of yaya because the `Eq (Nu f)` instance is+-- needed.+prop_nuAnaRefl :: Property+prop_nuAnaRefl =+ property $ law_anaRefl =<< forAll (Gen.sized genNuExpr) prop_nuCataCancel :: Property prop_nuCataCancel =
yaya-unsafe.cabal view
@@ -1,5 +1,5 @@ name: yaya-unsafe-version: 0.1.0.0+version: 0.1.1.0 synopsis: Non-total extensions to the Yaya recursion scheme library. description: Yaya is designed as a _total_ library. However, it is often expedient to use partial operations in some cases, and this@@ -18,7 +18,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@@ -32,7 +33,7 @@ , either , free , lens- , yaya+ , yaya >= 0.1.0 default-extensions: ConstraintKinds , DeriveTraversable , FlexibleContexts@@ -52,9 +53,9 @@ other-modules: Test.Fold build-depends: base , hedgehog- , yaya- , yaya-hedgehog- , yaya-unsafe+ , yaya >= 0.1.0+ , yaya-hedgehog >= 0.1.1+ , yaya-unsafe >= 0.1.0 ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall default-language: Haskell2010