monadic-recursion-schemes (empty) → 0.1.0.0
raw patch · 6 files changed
+148/−0 lines, 6 filesdep +basedep +comonaddep +containerssetup-changed
Dependencies added: base, comonad, containers, free, mtl, recursion-schemes, transformers
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- monadic-recursion-schemes.cabal +39/−0
- src/Data/Functor/Foldable/Monadic.hs +68/−0
- test/MyLibTest.hs +4/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for monadic-recursion-schemes++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2020, cutsea110++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of cutsea110 nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ monadic-recursion-schemes.cabal view
@@ -0,0 +1,39 @@+cabal-version: 2.4+-- Initial package description 'monadic-recursion-schemes.cabal' generated+-- by 'cabal init'. For further documentation, see+-- http://haskell.org/cabal/users-guide/++name: monadic-recursion-schemes+version: 0.1.0.0+synopsis: Recursion Schemes for Monadic version.+description: Yet another recursion schemes for monadic style, depends on recursion-schemes.+homepage: https://github.com/cutsea110/monadic-recursion-schemes.git+-- bug-reports:+license: BSD-3-Clause+license-file: LICENSE+author: cutsea110+maintainer: cutsea110@gmail.com+-- copyright:+category: Control, Recursion, Monad+extra-source-files: CHANGELOG.md++library+ exposed-modules: Data.Functor.Foldable.Monadic+ -- other-modules:+ -- other-extensions:+ build-depends: base ^>=4.12.0.0,+ containers >=0.6,+ mtl >=2.2.2,+ transformers >=0.5.6,+ recursion-schemes >=5.1.3,+ comonad >=5.0,+ free >=5.1.3+ hs-source-dirs: src+ default-language: Haskell2010++test-suite monadic-recursion-schemes-test+ default-language: Haskell2010+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: MyLibTest.hs+ build-depends: base ^>=4.12.0.0
+ src/Data/Functor/Foldable/Monadic.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE DeriveFoldable #-}+{-# LANGUAGE DeriveTraversable #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE FlexibleContexts #-}+module Data.Functor.Foldable.Monadic+ ( cataM, anaM+ , paraM, apoM+ , histoM, futuM+ , zygoM, cozygoM+ , hyloM+ ) where++import Control.Comonad (Comonad (..))+import Control.Comonad.Cofree (Cofree (..))+import Control.Monad ((<=<), liftM2)+import Control.Monad.Free (Free (..))+import Control.Monad.Trans.Class (lift)+import Control.Monad.Trans.Reader (ReaderT, ask, runReaderT)+import Data.Functor.Foldable (Recursive (..), Corecursive (..), Base, Fix (..))+++cataM :: (Monad m, Traversable (Base t), Recursive t)+ => (Base t a -> m a) -> t -> m a+cataM phi = h+ where h = phi <=< mapM h . project++anaM :: (Monad m, Traversable (Base t), Corecursive t)+ => (a -> m (Base t a)) -> a -> m t+anaM psi = h+ where h = (return . embed) <=< mapM h <=< psi++paraM :: (Monad m, Traversable (Base t), Recursive t)+ => (Base t (t, a) -> m a) -> t -> m a+paraM phi = h+ where h = phi <=< mapM (liftM2 (,) <$> return <*> h) . project++apoM :: (Monad m, Traversable (Base t), Corecursive t)+ => (a -> m (Base t (Either t a))) -> a -> m t+apoM psi = h+ where h = (return . embed) <=< mapM (either return h) <=< psi++histoM :: (Monad m, Traversable (Base t), Recursive t)+ => (Base t (Cofree (Base t) a) -> m a) -> t -> m a+histoM phi = return . extract <=< cataM f+ where f = return . uncurry (:<) <=< (liftM2 (,) <$> phi <*> return)++futuM :: (Monad m, Traversable (Base t), Corecursive t)+ => (a -> m (Base t (Free (Base t) a))) -> a -> m t+futuM psi = anaM f . Pure+ where f (Pure a) = psi a+ f (Free fb) = return fb++zygoM :: (Monad m, Traversable (Base t), Recursive t)+ => (Base t a -> m a) -> (Base t (a, b) -> m b) -> t -> m b+zygoM f phi = return . snd <=< cataM g+ where g = liftM2 (,) <$> (f <=< return . fmap fst) <*> phi++cozygoM :: (Monad m, Traversable (Base t), Corecursive t)+ => (a -> m (Base t a)) -> (b -> m (Base t (Either a b))) -> b -> m t+cozygoM f psi = anaM g . Right+ where g = either (return . fmap Left <=< f) psi++hyloM :: (Monad m, Traversable t)+ => (t b -> m b) -> (a -> m (t a)) -> a -> m b+hyloM phi psi = h+ where h = phi <=< mapM h <=< psi+
+ test/MyLibTest.hs view
@@ -0,0 +1,4 @@+module Main (main) where++main :: IO ()+main = putStrLn "Test suite not yet implemented."