indexed-free 0.2.1 → 0.3.0
raw patch · 3 files changed
+53/−3 lines, 3 files
Files
Control/Monad/Indexed/Free.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : provisional -- Portability : non-portable --
+ Control/MonadPlus/Indexed/Free.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE GADTs, FlexibleInstances #-} +module Control.MonadPlus.Indexed.Free (IxFree(..), module Control.Monad.Indexed.Free.Class) where + +import Control.Applicative +import Control.Monad.Indexed +import Control.Monad.Indexed.Free.Class + +data IxFree f i j x where + Pure :: a -> IxFree f i i a + Free :: f i j (IxFree f j k a) -> IxFree f i k a + Plus :: [IxFree f i j a] -> IxFree f i j a + +instance IxFunctor f => IxFunctor (IxFree f) where + imap f (Pure a) = Pure (f a) + imap f (Free w) = Free (imap (imap f) w) + imap f (Plus s) = Plus (map (imap f) s) + +instance IxFunctor f => IxPointed (IxFree f) where + ireturn = Pure + +instance IxFunctor f => IxApplicative (IxFree f) where + iap (Pure a) (Pure b) = Pure (a b) + iap (Pure a) (Free fb) = Free (imap a `imap` fb) + iap (Free fa) mb = Free $ imap (`iap` mb) fa + +instance IxFunctor f => IxMonadZero (IxFree f) where + imzero = Plus [] + +instance IxFunctor f => IxMonad (IxFree f) where + ibind k (Pure a) = k a + ibind k (Free fm) = Free $ imap (ibind k) fm + ibind k (Plus m) = Plus (map (ibind k) m) + +instance IxFunctor f => IxMonadPlus (IxFree f) where + Plus [] `implus` r = r + l `implus` Plus [] = l + Plus as `implus` Plus bs = Plus (as ++ bs) + a `implus` b = Plus [a, b] + +instance IxFunctor f => Functor (IxFree f i i) where + fmap = imap + +instance IxFunctor f => Applicative (IxFree f i i) where + pure = ireturn + (<*>) = iap + +instance IxFunctor f => Monad (IxFree f i i) where + return = ireturn + (>>=) = (>>>=) +
indexed-free.cabal view
@@ -1,5 +1,5 @@ name: indexed-free -version: 0.2.1 +version: 0.3.0 synopsis: indexed monads for free description: A free indexed monad homepage: https://github.com/fumieval/indexed-free @@ -17,6 +17,6 @@ location: https://github.com/fumieval/indexed-free.git library - exposed-modules: Control.Monad.Indexed.Free, Control.Monad.Indexed.Free.Class, Control.Monad.Indexed.Trans.Free + exposed-modules: Control.Monad.Indexed.Free, Control.Monad.Indexed.Free.Class, Control.Monad.Indexed.Trans.Free, Control.MonadPlus.Indexed.Free build-depends: base ==4.*, indexed < 0.2