From 3ac9b651b42469898e431ee075461ec49639225e Mon Sep 17 00:00:00 2001 From: rinse Date: Fri, 3 Jan 2025 19:55:16 +0900 Subject: [PATCH 1/4] Add QualifiedDo support for GHC>=9.0.1 --- Control/Monad/Indexed/QualifiedDo.hs | 47 ++++++++++++++++++++++++++++ indexed.cabal | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Control/Monad/Indexed/QualifiedDo.hs diff --git a/Control/Monad/Indexed/QualifiedDo.hs b/Control/Monad/Indexed/QualifiedDo.hs new file mode 100644 index 0000000..10d795d --- /dev/null +++ b/Control/Monad/Indexed/QualifiedDo.hs @@ -0,0 +1,47 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Indexed.QualifiedDo +-- Copyright : (C) 2025 Rinse +-- License : BSD-style (see the file LICENSE) +-- +-- Maintainer : +-- Stability : experimental +-- Portability : portable +-- +---------------------------------------------------------------------------- +module Control.Monad.Indexed.QualifiedDo + ( (>>=), (>>), return, fail + , fmap, (<*>), join, mfix + ) where + +import Control.Monad.Indexed +import Control.Monad.Indexed.Fix +import qualified Prelude + +infixl 1 >>=, >> + +(>>=) :: IxMonad m => m i j a -> (a -> m j k b) -> m i k b +m >>= f = ibind f m + +(>>) :: IxMonad m => m i j a -> m j k b -> m i k b +m >> n = m >>= \_ -> n + +return :: IxPointed m => a -> m i i a +return = ireturn + +fail :: IxMonadFail m => Prelude.String -> m i i a +fail = ifail + +fmap :: IxFunctor f => (a -> b) -> f j k a -> f j k b +fmap = imap + +infixl 4 <*> + +(<*>) :: IxApplicative m => m i j (a -> b) -> m j k a -> m i k b +(<*>) = iap + +join :: IxMonad m => m i j (m j k a) -> m i k a +join = ijoin + +mfix :: IxMonadFix m => (a -> m i i a) -> m i i a +mfix = imfix diff --git a/indexed.cabal b/indexed.cabal index ee9df23..cfa3491 100644 --- a/indexed.cabal +++ b/indexed.cabal @@ -26,7 +26,8 @@ Library Data.Functor.Indexed, Control.Monad.Indexed, Control.Monad.Indexed.Fix, - Control.Monad.Indexed.Trans + Control.Monad.Indexed.Trans, + Control.Monad.Indexed.QualifiedDo Control.Comonad.Indexed default-language: Haskell98 if impl(ghc >= 7.5) From 9cf9e97d08c6f958241c04d298022ac10e6dee21 Mon Sep 17 00:00:00 2001 From: rinse Date: Fri, 3 Jan 2025 20:08:03 +0900 Subject: [PATCH 2/4] Add IxMonadFail for fail --- Control/Monad/Indexed.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Control/Monad/Indexed.hs b/Control/Monad/Indexed.hs index dcb5995..359e9ab 100644 --- a/Control/Monad/Indexed.hs +++ b/Control/Monad/Indexed.hs @@ -16,6 +16,7 @@ module Control.Monad.Indexed , IxMonad(..) , IxMonadZero(..) , IxMonadPlus(..) + , IxMonadFail(..) , ijoin, (>>>=), (=<<<) , iapIxMonad ) where @@ -45,3 +46,6 @@ class IxMonad m => IxMonadZero m where class IxMonadZero m => IxMonadPlus m where implus :: m i j a -> m i j a -> m i j a + +class IxMonad m => IxMonadFail m where + ifail :: String -> m i i a From 0c4efa5350468471f417db2053551bb5862837df Mon Sep 17 00:00:00 2001 From: rinse Date: Fri, 3 Jan 2025 21:12:25 +0900 Subject: [PATCH 3/4] Move IxMonadFail to a separate module --- Control/Monad/Indexed.hs | 4 ---- Control/Monad/Indexed/Fail.hs | 8 ++++++++ Control/Monad/Indexed/QualifiedDo.hs | 1 + indexed.cabal | 5 +++-- 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 Control/Monad/Indexed/Fail.hs diff --git a/Control/Monad/Indexed.hs b/Control/Monad/Indexed.hs index 359e9ab..dcb5995 100644 --- a/Control/Monad/Indexed.hs +++ b/Control/Monad/Indexed.hs @@ -16,7 +16,6 @@ module Control.Monad.Indexed , IxMonad(..) , IxMonadZero(..) , IxMonadPlus(..) - , IxMonadFail(..) , ijoin, (>>>=), (=<<<) , iapIxMonad ) where @@ -46,6 +45,3 @@ class IxMonad m => IxMonadZero m where class IxMonadZero m => IxMonadPlus m where implus :: m i j a -> m i j a -> m i j a - -class IxMonad m => IxMonadFail m where - ifail :: String -> m i i a diff --git a/Control/Monad/Indexed/Fail.hs b/Control/Monad/Indexed/Fail.hs new file mode 100644 index 0000000..ba0597f --- /dev/null +++ b/Control/Monad/Indexed/Fail.hs @@ -0,0 +1,8 @@ +module Control.Monad.Indexed.Fail + ( IxMonadFail(..) + ) where + +import Control.Monad.Indexed + +class IxMonad m => IxMonadFail m where + ifail :: String -> m i i a diff --git a/Control/Monad/Indexed/QualifiedDo.hs b/Control/Monad/Indexed/QualifiedDo.hs index 10d795d..c91c383 100644 --- a/Control/Monad/Indexed/QualifiedDo.hs +++ b/Control/Monad/Indexed/QualifiedDo.hs @@ -15,6 +15,7 @@ module Control.Monad.Indexed.QualifiedDo ) where import Control.Monad.Indexed +import Control.Monad.Indexed.Fail import Control.Monad.Indexed.Fix import qualified Prelude diff --git a/indexed.cabal b/indexed.cabal index cfa3491..52f9c46 100644 --- a/indexed.cabal +++ b/indexed.cabal @@ -25,9 +25,10 @@ Library Exposed-modules: Data.Functor.Indexed, Control.Monad.Indexed, + Control.Monad.Indexed.Fail, Control.Monad.Indexed.Fix, - Control.Monad.Indexed.Trans, - Control.Monad.Indexed.QualifiedDo + Control.Monad.Indexed.QualifiedDo, + Control.Monad.Indexed.Trans Control.Comonad.Indexed default-language: Haskell98 if impl(ghc >= 7.5) From d8bb7b3b46b8ac36bd7b7f38c9baa8600b7b51e9 Mon Sep 17 00:00:00 2001 From: rinse Date: Fri, 3 Jan 2025 21:35:15 +0900 Subject: [PATCH 4/4] Add description to the Fail module --- Control/Monad/Indexed/Fail.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Control/Monad/Indexed/Fail.hs b/Control/Monad/Indexed/Fail.hs index ba0597f..1175df4 100644 --- a/Control/Monad/Indexed/Fail.hs +++ b/Control/Monad/Indexed/Fail.hs @@ -1,3 +1,14 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Indexed.Fail +-- Copyright : (C) 2025 Rinse +-- License : BSD-style (see the file LICENSE) +-- +-- Maintainer : +-- Stability : experimental +-- Portability : portable +-- +---------------------------------------------------------------------------- module Control.Monad.Indexed.Fail ( IxMonadFail(..) ) where