diff options
| author | Inari Listenmaa <inari.listenmaa@gmail.com> | 2024-09-09 19:43:39 +0200 |
|---|---|---|
| committer | Inari Listenmaa <inari.listenmaa@gmail.com> | 2025-08-02 16:39:31 +0200 |
| commit | b914a25de326dd937e3a1d05f4eefb46af6da7b4 (patch) | |
| tree | e816d5ec4b91425f3f7e41dd8bd75a2681ff524c /src/compiler/GF | |
| parent | 1037b209ae225d5de604ff832d915c590ced4c38 (diff) | |
define return in terms of pure, >> as *>, mappend as <>
In preparation for deprecation, see https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid and https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
Diffstat (limited to 'src/compiler/GF')
| -rw-r--r-- | src/compiler/GF/Compile/GeneratePMCFG.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/CompileInParallel.hs | 6 | ||||
| -rw-r--r-- | src/compiler/GF/Data/BacktrackM.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Data/ErrM.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Grammar/Lexer.x | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Infra/CheckM.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Infra/SIO.hs | 4 |
8 files changed, 17 insertions, 17 deletions
diff --git a/src/compiler/GF/Compile/GeneratePMCFG.hs b/src/compiler/GF/Compile/GeneratePMCFG.hs index 8383f0624..74615dc98 100644 --- a/src/compiler/GF/Compile/GeneratePMCFG.hs +++ b/src/compiler/GF/Compile/GeneratePMCFG.hs @@ -201,11 +201,11 @@ instance Fail.MonadFail CnvMonad where fail = bug instance Applicative CnvMonad where - pure = return + pure a = CM (\gr c s -> c a s) (<*>) = ap instance Monad CnvMonad where - return a = CM (\gr c s -> c a s) + return = pure CM m >>= k = CM (\gr c s -> m gr (\a s -> unCM (k a) gr c s) s) instance MonadState ([ProtoFCat],[Symbol]) CnvMonad where diff --git a/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs b/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs index ed3a20ce0..0e76c3205 100644 --- a/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs +++ b/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs @@ -644,7 +644,7 @@ data TcResult a newtype TcM a = TcM {unTcM :: MetaStore -> [Message] -> TcResult a} instance Monad TcM where - return x = TcM (\ms msgs -> TcOk x ms msgs) + return = pure f >>= g = TcM (\ms msgs -> case unTcM f ms msgs of TcOk x ms msgs -> unTcM (g x) ms msgs TcFail msgs -> TcFail msgs) @@ -659,7 +659,7 @@ instance Fail.MonadFail TcM where instance Applicative TcM where - pure = return + pure x = TcM (\ms msgs -> TcOk x ms msgs) (<*>) = ap instance Functor TcM where diff --git a/src/compiler/GF/CompileInParallel.hs b/src/compiler/GF/CompileInParallel.hs index ceb1b99b5..11f806175 100644 --- a/src/compiler/GF/CompileInParallel.hs +++ b/src/compiler/GF/CompileInParallel.hs @@ -238,12 +238,12 @@ runCO (CO m) = do (o,x) <- m instance Functor m => Functor (CollectOutput m) where fmap f (CO m) = CO (fmap (fmap f) m) -instance (Functor m,Monad m) => Applicative (CollectOutput m) where - pure = return +instance (Functor m,Monad m) => Applicative (CollectOutput m) where + pure x = CO (return (return (),x)) (<*>) = ap instance Monad m => Monad (CollectOutput m) where - return x = CO (return (return (),x)) + return = pure CO m >>= f = CO $ do (o1,x) <- m let CO m2 = f x (o2,y) <- m2 diff --git a/src/compiler/GF/Data/BacktrackM.hs b/src/compiler/GF/Data/BacktrackM.hs index 970de5c06..69bc2c29b 100644 --- a/src/compiler/GF/Data/BacktrackM.hs +++ b/src/compiler/GF/Data/BacktrackM.hs @@ -64,11 +64,11 @@ finalStates :: BacktrackM s () -> s -> [s] finalStates bm = map fst . runBM bm instance Applicative (BacktrackM s) where - pure = return + pure a = BM (\c s b -> c a s b) (<*>) = ap instance Monad (BacktrackM s) where - return a = BM (\c s b -> c a s b) + return = pure BM m >>= k = BM (\c s b -> m (\a s b -> unBM (k a) c s b) s b) where unBM (BM m) = m diff --git a/src/compiler/GF/Data/ErrM.hs b/src/compiler/GF/Data/ErrM.hs index 288c61919..133a49b73 100644 --- a/src/compiler/GF/Data/ErrM.hs +++ b/src/compiler/GF/Data/ErrM.hs @@ -34,7 +34,7 @@ fromErr :: a -> Err a -> a fromErr a = err (const a) id instance Monad Err where - return = Ok + return = pure Ok a >>= f = f a Bad s >>= f = Bad s @@ -54,7 +54,7 @@ instance Functor Err where fmap f (Bad s) = Bad s instance Applicative Err where - pure = return + pure = Ok (<*>) = ap -- | added by KJ diff --git a/src/compiler/GF/Grammar/Lexer.x b/src/compiler/GF/Grammar/Lexer.x index b3d271ddd..248d091a1 100644 --- a/src/compiler/GF/Grammar/Lexer.x +++ b/src/compiler/GF/Grammar/Lexer.x @@ -283,11 +283,11 @@ instance Functor P where fmap = liftA instance Applicative P where - pure = return + pure a = a `seq` (P $ \s -> POk s a) (<*>) = ap instance Monad P where - return a = a `seq` (P $ \s -> POk s a) + return = pure (P m) >>= k = P $ \ s -> case m s of POk s a -> unP (k a) s PFailed posn err -> PFailed posn err diff --git a/src/compiler/GF/Infra/CheckM.hs b/src/compiler/GF/Infra/CheckM.hs index a5ff7148a..1dd26dd5c 100644 --- a/src/compiler/GF/Infra/CheckM.hs +++ b/src/compiler/GF/Infra/CheckM.hs @@ -48,7 +48,7 @@ newtype Check a instance Functor Check where fmap = liftM instance Monad Check where - return x = Check $ \{-ctxt-} ws -> (ws,Success x) + return = pure f >>= g = Check $ \{-ctxt-} ws -> case unCheck f {-ctxt-} ws of (ws,Success x) -> unCheck (g x) {-ctxt-} ws @@ -58,7 +58,7 @@ instance Fail.MonadFail Check where fail = raise instance Applicative Check where - pure = return + pure x = Check $ \{-ctxt-} ws -> (ws,Success x) (<*>) = ap instance ErrorMonad Check where diff --git a/src/compiler/GF/Infra/SIO.hs b/src/compiler/GF/Infra/SIO.hs index 906f39345..7b5a7dac6 100644 --- a/src/compiler/GF/Infra/SIO.hs +++ b/src/compiler/GF/Infra/SIO.hs @@ -52,11 +52,11 @@ newtype SIO a = SIO {unS::PutStr->IO a} instance Functor SIO where fmap = liftM instance Applicative SIO where - pure = return + pure x = SIO (const (pure x)) (<*>) = ap instance Monad SIO where - return x = SIO (const (return x)) + return = pure SIO m1 >>= xm2 = SIO $ \ h -> m1 h >>= \ x -> unS (xm2 x) h instance Fail.MonadFail SIO where |
