Skip to content

Commit ef34928

Browse files
authored
tests/default_typeclass: move def of return to pure (#188)
* tests/default_typeclass: move def of return to pure Moving the definition of the `return` of the StateT monad to the `Applicative` instance, to `pure`, fixes these warnings (which fail the testsuite under `-Werror=noncanonical-monad-instances`): Noncanonical ‘return’ definition detected in the instance declaration for ‘Monad (StateT s m)’. ‘return’ will eventually be removed in favour of ‘pure’ Either remove definition for ‘return’ (recommended) or define as ‘return = pure’ Noncanonical ‘pure = return’ definition detected in the instance declaration for ‘Applicative (StateT s m)’. Move definition from ‘return’ to ‘pure’ * tests/default_typeclass: move def of return to pure (fixup) Note: Requires additional Functor constraints for older GHC versions.
1 parent fbcb2e0 commit ef34928

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/default_typeclass.x

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,34 +280,34 @@ instance (Functor m) => Functor (StateT s m) where
280280
fmap f m = StateT $ \ s ->
281281
fmap (\ (a, s') -> (f a, s')) $ runStateT m s
282282

283-
instance (Monad m) => Monad (StateT s m) where
284-
return a = state $ \s -> (a, s)
283+
instance (Functor m, Monad m) => Monad (StateT s m) where
284+
return = pure
285285
m >>= k = StateT $ \s -> do
286286
(a, s') <- runStateT m s
287287
runStateT (k a) s'
288288

289289
-- | Fetch the current value of the state within the monad.
290-
get' :: (Monad m) => StateT s m s
290+
get' :: (Functor m, Monad m) => StateT s m s
291291
get' = state $ \s -> (s, s)
292292

293293
-- | @'put' s@ sets the state within the monad to @s@.
294-
put' :: (Monad m) => s -> StateT s m ()
294+
put' :: (Functor m, Monad m) => s -> StateT s m ()
295295
put' s = state $ \_ -> ((), s)
296296

297297
-- | @'modify' f@ is an action that updates the state to the result of
298298
-- applying @f@ to the current state.
299299
--
300300
-- * @'modify' f = 'get' >>= ('put' . f)@
301-
modify' :: (Monad m) => (s -> s) -> StateT s m ()
301+
modify' :: (Functor m, Monad m) => (s -> s) -> StateT s m ()
302302
modify' f = state $ \s -> ((), f s)
303303

304-
instance Monad m => MonadState s (StateT s m) where
304+
instance (Functor m, Monad m) => MonadState s (StateT s m) where
305305
get = get'
306306
put = put'
307307
state = state'
308308
309309
instance (Functor m, Monad m) => Applicative (StateT s m) where
310-
pure = return
310+
pure a = state $ \s -> (a, s)
311311
(<*>) = ap
312312
313313
}

0 commit comments

Comments
 (0)