From 80ee55860f2d5a9851ea57b9cd20c53b2d3955eb Mon Sep 17 00:00:00 2001 From: Nathan Faubion Date: Tue, 11 Apr 2017 14:58:52 -0500 Subject: [PATCH] Updates for 0.11 (#7) --- bower.json | 11 ++-- package.json | 6 +- src/Matryoshka/DistributiveLaw.purs | 21 ++++--- src/Matryoshka/Fold.purs | 86 ++++++++++++++++++++--------- src/Matryoshka/Refold.purs | 23 ++++++-- src/Matryoshka/Unfold.purs | 58 +++++++++++++------ src/Matryoshka/Util.purs | 6 +- 7 files changed, 145 insertions(+), 66 deletions(-) diff --git a/bower.json b/bower.json index d094919..787100c 100644 --- a/bower.json +++ b/bower.json @@ -15,13 +15,12 @@ "package.json" ], "dependencies": { - "purescript-fixed-points": "^3.0.0", - "purescript-free": "^3.2.0", - "purescript-transformers": "^2.0.2", - "purescript-profunctor": "^2.0.0" + "purescript-fixed-points": "^4.0.0", + "purescript-free": "^4.0.0", + "purescript-transformers": "^3.0.0", + "purescript-profunctor": "^3.0.0" }, "devDependencies": { - "purescript-console": "^2.0.0" + "purescript-console": "^3.0.0" } - } diff --git a/package.json b/package.json index 3446d1c..312b8a7 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "test": "pulp test -- --censor-lib --strict" }, "devDependencies": { - "pulp": "^10.0.0", - "purescript": "^0.10.3", - "purescript-psa": "^0.4.0", + "pulp": "^11.0.0", + "purescript": "^0.11.3", + "purescript-psa": "^0.5.0", "rimraf": "^2.5.4" } } diff --git a/src/Matryoshka/DistributiveLaw.purs b/src/Matryoshka/DistributiveLaw.purs index 9fb323b..dd16276 100644 --- a/src/Matryoshka/DistributiveLaw.purs +++ b/src/Matryoshka/DistributiveLaw.purs @@ -39,10 +39,10 @@ import Matryoshka.Coalgebra (Coalgebra) type DistributiveLaw f g = ∀ a. f (g a) → g (f a) -distApplicative ∷ ∀ f g. (Traversable f, Applicative g) ⇒ DistributiveLaw f g +distApplicative ∷ ∀ f g. Traversable f ⇒ Applicative g ⇒ DistributiveLaw f g distApplicative = sequence -distDistributive ∷ ∀ f g. (Traversable f, Distributive g) ⇒ DistributiveLaw f g +distDistributive ∷ ∀ f g. Traversable f ⇒ Distributive g ⇒ DistributiveLaw f g distDistributive = distribute distCata ∷ ∀ f. Functor f ⇒ DistributiveLaw f Identity @@ -53,7 +53,8 @@ distPara = distZygo embed distParaT ∷ ∀ t f w - . (Corecursive t f, Comonad w) + . Corecursive t f + ⇒ Comonad w ⇒ DistributiveLaw f w → DistributiveLaw f (EnvT t w) distParaT = distZygoT embed @@ -63,7 +64,8 @@ distZygo g m = Tuple (g (map fst m)) (map snd m) distZygoT ∷ ∀ f w a - . (Functor f, Comonad w) + . Functor f + ⇒ Comonad w ⇒ Algebra f a → DistributiveLaw f w → DistributiveLaw f (EnvT a w) @@ -75,10 +77,11 @@ distHisto = distGHisto id distGHisto ∷ ∀ f h - . (Functor f, Functor h) + . Functor f + ⇒ Functor h ⇒ DistributiveLaw f h → DistributiveLaw f (Cofree h) -distGHisto k x = unfoldCofree x (map extract) (k <<< map tail) +distGHisto k = unfoldCofree (map extract) (k <<< map tail) distAna ∷ ∀ f. Functor f ⇒ DistributiveLaw Identity f distAna = map wrap <<< unwrap @@ -91,7 +94,8 @@ distGApo f = either (map Left <<< f) (map Right) distGApoT ∷ ∀ f m a - . (Functor f, Functor m) + . Functor f + ⇒ Functor m ⇒ Coalgebra f a → DistributiveLaw m f → DistributiveLaw (ExceptT a m) f @@ -102,7 +106,8 @@ distFutu = distGFutu id distGFutu ∷ ∀ f h - . (Functor f, Functor h) + . Functor f + ⇒ Functor h ⇒ DistributiveLaw h f → DistributiveLaw (Free h) f distGFutu k f = case resume f of diff --git a/src/Matryoshka/Fold.purs b/src/Matryoshka/Fold.purs index 9e47833..b1b4781 100644 --- a/src/Matryoshka/Fold.purs +++ b/src/Matryoshka/Fold.purs @@ -44,7 +44,9 @@ cata f = go cataM ∷ ∀ t f m a - . (Recursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ AlgebraM m f a → t → m a @@ -54,7 +56,8 @@ cataM f = go gcata ∷ ∀ t f w a - . (Recursive t f, Comonad w) + . Recursive t f + ⇒ Comonad w ⇒ DistributiveLaw f w → GAlgebra w f a → t @@ -65,7 +68,11 @@ gcata k g = g <<< extract <<< go gcataM ∷ ∀ t f w m a - . (Recursive t f, Monad m, Comonad w, Traversable f, Traversable w) + . Recursive t f + ⇒ Monad m + ⇒ Comonad w + ⇒ Traversable f + ⇒ Traversable w ⇒ DistributiveLaw f w → GAlgebraM w m f a → t @@ -76,7 +83,8 @@ gcataM k g = g <<< extract <=< loop elgotCata ∷ ∀ t f w a - . (Recursive t f, Comonad w) + . Recursive t f + ⇒ Comonad w ⇒ DistributiveLaw f w → ElgotAlgebra w f a → t @@ -87,7 +95,8 @@ elgotCata k g = g <<< go transCata ∷ ∀ t f u g - . (Recursive t f, Corecursive u g) + . Recursive t f + ⇒ Corecursive u g ⇒ Transform u f g → t → u @@ -97,7 +106,8 @@ transCata f = go transCataT ∷ ∀ t f - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (t → t) → t → t @@ -107,7 +117,10 @@ transCataT f = go transCataM ∷ ∀ t f u g m - . (Recursive t f, Corecursive u g, Monad m, Traversable f) + . Recursive t f + ⇒ Corecursive u g + ⇒ Monad m + ⇒ Traversable f ⇒ TransformM m u f g → t → m u @@ -117,7 +130,10 @@ transCataM f = go transCataTM ∷ ∀ t f m - . (Recursive t f, Corecursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ (t → m t) → t → m t @@ -127,7 +143,8 @@ transCataTM f = go topDownCata ∷ ∀ t f a - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (a → t → Tuple a t) → a → t @@ -139,7 +156,10 @@ topDownCata f = go topDownCataM ∷ ∀ t f m a - . (Recursive t f, Corecursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ (a → t → m (Tuple a t)) → a → t @@ -151,7 +171,8 @@ topDownCataM f = go prepro ∷ ∀ t f a - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (f ~> f) → Algebra f a → t @@ -162,7 +183,9 @@ prepro f g = go gprepro ∷ ∀ t f w a - . (Recursive t f, Corecursive t f, Comonad w) + . Recursive t f + ⇒ Corecursive t f + ⇒ Comonad w ⇒ DistributiveLaw f w → (f ~> f) → GAlgebra w f a @@ -174,7 +197,9 @@ gprepro f g h = extract <<< go transPrepro ∷ ∀ t f u g - . (Recursive t f, Corecursive t f, Corecursive u g) + . Recursive t f + ⇒ Corecursive t f + ⇒ Corecursive u g ⇒ (f ~> f) → Transform u f g → t @@ -191,7 +216,9 @@ para f = go paraM ∷ ∀ t f m a - . (Recursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ GAlgebraM (Tuple t) m f a → t → m a @@ -201,7 +228,9 @@ paraM f = go gpara ∷ ∀ t f w a - . (Recursive t f, Corecursive t f, Comonad w) + . Recursive t f + ⇒ Corecursive t f + ⇒ Comonad w ⇒ DistributiveLaw f w → GAlgebra (EnvT t w) f a → t @@ -215,7 +244,8 @@ elgotPara f = go transPara ∷ ∀ t f u g - . (Recursive t f, Corecursive u g) + . Recursive t f + ⇒ Corecursive u g ⇒ AlgebraicGTransform (Tuple t) u f g → t → u @@ -225,7 +255,8 @@ transPara f = go transParaT ∷ ∀ t f - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (t → t → t) → t → t @@ -244,7 +275,8 @@ zygo = gcata <<< distZygo gzygo ∷ ∀ t f w a b - . (Recursive t f, Comonad w) + . Recursive t f + ⇒ Comonad w ⇒ Algebra f b → DistributiveLaw f w → GAlgebra (EnvT b w) f a @@ -263,7 +295,8 @@ elgotZygo = elgotCata <<< distZygo gElgotZygo ∷ ∀ t f w a b - . (Recursive t f, Comonad w) + . Recursive t f + ⇒ Comonad w ⇒ Algebra f b → DistributiveLaw f w → ElgotAlgebra (EnvT b w) f a @@ -292,7 +325,8 @@ histo = gcata distHisto ghisto ∷ ∀ t f h a - . (Recursive t f, Functor h) + . Recursive t f + ⇒ Functor h ⇒ DistributiveLaw f h → GAlgebra (Cofree h) f a → t @@ -322,7 +356,9 @@ annotateTopDown f z = go annotateTopDownM ∷ ∀ t f m a - . (Recursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ (a → f t → m a) → a → t @@ -333,14 +369,14 @@ annotateTopDownM f z = go let ft = project t in (flip map (traverse go ft) <<< mkCofree) =<< f z ft -isLeaf ∷ ∀ t f. (Recursive t f, Foldable f) ⇒ t → Boolean +isLeaf ∷ ∀ t f. Recursive t f ⇒ Foldable f ⇒ t → Boolean isLeaf t = alaF Disj foldMap (const true) (project t) -children ∷ ∀ t f. (Recursive t f, Foldable f) ⇒ t → List t +children ∷ ∀ t f. Recursive t f ⇒ Foldable f ⇒ t → List t children = foldMap pure <<< project -universe ∷ ∀ t f. (Recursive t f, Foldable f) ⇒ t → List t +universe ∷ ∀ t f. Recursive t f ⇒ Foldable f ⇒ t → List t universe t = universe =<< children t -lambek ∷ ∀ t f. (Recursive t f, Corecursive t f) ⇒ t → f t +lambek ∷ ∀ t f. Recursive t f ⇒ Corecursive t f ⇒ t → f t lambek = cata (map embed) diff --git a/src/Matryoshka/Refold.purs b/src/Matryoshka/Refold.purs index 778ffa1..aaa2b34 100644 --- a/src/Matryoshka/Refold.purs +++ b/src/Matryoshka/Refold.purs @@ -49,7 +49,8 @@ hylo f g = go hyloM ∷ ∀ f m a b - . (Monad m, Traversable f) + . Monad m + ⇒ Traversable f ⇒ AlgebraM m f b → CoalgebraM m f a → a @@ -60,7 +61,9 @@ hyloM f g = go ghylo ∷ ∀ f w n a b - . (Monad n, Comonad w, Functor f) + . Monad n + ⇒ Comonad w + ⇒ Functor f ⇒ DistributiveLaw f w → DistributiveLaw n f → GAlgebra w f b @@ -73,7 +76,12 @@ ghylo w n f g = extract <<< go <<< pure ghyloM ∷ ∀ f w n m a b - . (Monad m, Monad n, Comonad w, Traversable f, Traversable w, Traversable n) + . Monad m + ⇒ Monad n + ⇒ Comonad w + ⇒ Traversable f + ⇒ Traversable w + ⇒ Traversable n ⇒ DistributiveLaw f w → DistributiveLaw n f → GAlgebraM w m f b @@ -86,7 +94,9 @@ ghyloM w m f g = map extract <<< h <<< pure transHylo ∷ ∀ t f g h u - . (Recursive t f, Corecursive u h, Functor g) + . Recursive t f + ⇒ Corecursive u h + ⇒ Functor g ⇒ Transform u g h → Transform t f g → t @@ -115,7 +125,8 @@ codyna f = ghylo distCata distFutu (lmap (map unwrap) f) codynaM ∷ ∀ f m a b - . (Monad m, Traversable f) + . Monad m + ⇒ Traversable f ⇒ AlgebraM m f b → GCoalgebraM (Free f) m f a → a @@ -131,5 +142,5 @@ chrono → b chrono = ghylo distHisto distFutu -convertTo ∷ ∀ t f r. (Recursive t f, Corecursive r f) ⇒ t → r +convertTo ∷ ∀ t f r. Recursive t f ⇒ Corecursive r f ⇒ t → r convertTo = cata embed diff --git a/src/Matryoshka/Unfold.purs b/src/Matryoshka/Unfold.purs index b6df713..3b8b68c 100644 --- a/src/Matryoshka/Unfold.purs +++ b/src/Matryoshka/Unfold.purs @@ -38,7 +38,9 @@ ana f = go anaM ∷ ∀ t f m a - . (Corecursive t f, Monad m, Traversable f) + . Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ CoalgebraM m f a → a → m t @@ -48,7 +50,8 @@ anaM f = go gana ∷ ∀ t f n a - . (Corecursive t f, Monad n) + . Corecursive t f + ⇒ Monad n ⇒ DistributiveLaw n f → GCoalgebra n f a → a @@ -59,7 +62,11 @@ gana k f = go <<< pure <<< f ganaM ∷ ∀ t f m n a - . (Corecursive t f, Monad m, Monad n, Traversable f, Traversable n) + . Corecursive t f + ⇒ Monad m + ⇒ Monad n + ⇒ Traversable f + ⇒ Traversable n ⇒ DistributiveLaw n f → GCoalgebraM n m f a → a @@ -70,7 +77,8 @@ ganaM k f = go <=< map pure <<< f elgotAna ∷ ∀ t f n a - . (Corecursive t f, Monad n) + . Corecursive t f + ⇒ Monad n ⇒ DistributiveLaw n f → ElgotCoalgebra n f a → a @@ -81,7 +89,8 @@ elgotAna k f = go <<< f transAna ∷ ∀ t f u g - . (Recursive t f, Corecursive u g) + . Recursive t f + ⇒ Corecursive u g ⇒ Transform t f g → t → u @@ -89,14 +98,17 @@ transAna f = go where go t = mapR (map go <<< f) t -transAnaT ∷ ∀ t f. (Recursive t f, Corecursive t f) ⇒ (t → t) → t → t +transAnaT ∷ ∀ t f. Recursive t f ⇒ Corecursive t f ⇒ (t → t) → t → t transAnaT f = go where go t = mapR (map go) (f t) transAnaM ∷ ∀ t f u g m - . (Recursive t f, Corecursive u g, Monad m, Traversable g) + . Recursive t f + ⇒ Corecursive u g + ⇒ Monad m + ⇒ Traversable g ⇒ TransformM m t f g → t → m u @@ -106,7 +118,10 @@ transAnaM f = go transAnaTM ∷ ∀ t f m - . (Recursive t f, Corecursive t f, Monad m, Traversable f) + . Recursive t f + ⇒ Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ Coalgebra m t → t → m t @@ -116,7 +131,8 @@ transAnaTM f = go postpro ∷ ∀ t f a - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (f ~> f) → Coalgebra f a → a @@ -125,7 +141,9 @@ postpro f g = gpostpro distAna f (map Identity <<< g) gpostpro ∷ ∀ t f n a - . (Recursive t f, Corecursive t f, Monad n) + . Recursive t f + ⇒ Corecursive t f + ⇒ Monad n ⇒ DistributiveLaw n f → (f ~> f) → GCoalgebra n f a @@ -137,7 +155,9 @@ gpostpro f g h = go <<< pure transPostpro ∷ ∀ t f u g - . (Recursive t f, Recursive u g, Corecursive u g) + . Recursive t f + ⇒ Recursive u g + ⇒ Corecursive u g ⇒ (g ~> g) → Transform t f g → t @@ -165,7 +185,9 @@ gapo f g = go apoM ∷ ∀ t f m a - . (Corecursive t f, Monad m, Traversable f) + . Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ GCoalgebraM (Either t) m f a → a → m t @@ -180,7 +202,8 @@ elgotApo f = go transApo ∷ ∀ t f u g - . (Recursive t f, Corecursive u g) + . Recursive t f + ⇒ Corecursive u g ⇒ CoalgebraicGTransform (Either u) t f g → t → u @@ -190,7 +213,8 @@ transApo f = go transApoT ∷ ∀ t f - . (Recursive t f, Corecursive t f) + . Recursive t f + ⇒ Corecursive t f ⇒ (t → Either t t) → t → t @@ -206,7 +230,9 @@ elgotFutu = elgotAna distFutu futuM ∷ ∀ t f m a - . (Corecursive t f, Monad m, Traversable f) + . Corecursive t f + ⇒ Monad m + ⇒ Traversable f ⇒ GCoalgebraM (Free f) m f a → a → m t @@ -215,5 +241,5 @@ futuM f = go go a = map embed <<< traverse loop =<< f a loop x = either (map embed <<< traverse loop) go (resume x) -colambek ∷ ∀ t f. (Recursive t f, Corecursive t f) ⇒ f t → t +colambek ∷ ∀ t f. Recursive t f ⇒ Corecursive t f ⇒ f t → t colambek = ana (map project) diff --git a/src/Matryoshka/Util.purs b/src/Matryoshka/Util.purs index ef1143f..c272fe3 100644 --- a/src/Matryoshka/Util.purs +++ b/src/Matryoshka/Util.purs @@ -21,12 +21,14 @@ import Prelude import Matryoshka.Class.Corecursive (class Corecursive, embed) import Matryoshka.Class.Recursive (class Recursive, project) -mapR ∷ ∀ t f u g. (Recursive t f, Corecursive u g) ⇒ (f t → g u) → t → u +mapR ∷ ∀ t f u g. Recursive t f ⇒ Corecursive u g ⇒ (f t → g u) → t → u mapR f = embed <<< f <<< project traverseR ∷ ∀ t f u g m - . (Recursive t f, Corecursive u g, Functor m) + . Recursive t f + ⇒ Corecursive u g + ⇒ Functor m ⇒ (f t → m (g u)) → t → m u