Description

This module provides alternatives to the `Functor`, `Monad` and `MonadPlus` classes, allowing for constraints on the contained type (a restricted monad). It makes use of associated datatypes (available in GHC 6.8).

To make your own type instances of these classes, first define the `Constraints` datatype and the `Suitable` type class for it. For example,

```     data instance Constraints Set a = Ord a => SetConstraints
instance Ord a => Suitable Set a where
constraints = SetConstraints
```

You need to change `Set` to your own type, `Ord a` to your own constraints, and `SetConstraints` to some distinguished name (this name will not normally be visible to users of your type)

Next you can make an instance of `RMonad` and if appropriate `RMonadPlus` by defining the members in the usual way. When you need to make use of the constraint on the contained type, you will need to get hold of the constraint wrapped up in the `Constraints` datatype, which can be achieved with the helper `withResConstraints`. For example here are the instances for `Set`:

```    instance RMonad Set where
return = Set.singleton
s >>= f = withResConstraints \$ SetConstraints -> Set.fold (a s' -> Set.union (f a) s') Set.empty s
fail _ = Set.empty
```
```    instance RMonadPlus Set where
mzero = Set.empty
mplus s1 s2 = withResConstraints \$ SetConstraints -> Set.union s1 s2
```

Once you have made your type an instance of `RMonad`, you can use it in two ways. Firstly, import this module directly and use the `RebindableSyntax` extension so that do-syntax is rebound. If using ghc<7 use `NoImplicitPrelude` instead. Secondly, use the wrapper type in Control.RMonad.AsMonad which supports the normal `Monad` operations.

# Documentation

class Suitable m a where

Methods

Instances

 Suitable [] a Suitable IO a Suitable Maybe a Ord a => Suitable Set a Suitable ((->) r) a (Suitable m a, Suitable m [a]) => Suitable (ListT m) a (Ord a, Suitable m a, Suitable m (Set a)) => Suitable (SetT m) a Suitable m a => Suitable (ReaderT r m) a (Suitable m a, Suitable m r) => Suitable (ContT r m) a

class RFunctor f whereSource

Methods

fmap :: (Suitable f a, Suitable f b) => (a -> b) -> f a -> f bSource

Instances

 RFunctor [] RFunctor IO RFunctor Maybe RFunctor Set RFunctor ((->) r)

Methods

return :: Suitable m a => a -> m aSource

(>>=) :: (Suitable m a, Suitable m b) => m a -> (a -> m b) -> m bSource

(>>) :: (Suitable m a, Suitable m b) => m a -> m b -> m bSource

fail :: Suitable m a => String -> m aSource

Instances

Methods

mzero :: Suitable m a => m aSource

mplus :: Suitable m a => m a -> m a -> m aSource

Instances

(<=<) :: (RMonad m, Suitable m a, Suitable m b, Suitable m c) => (b -> m c) -> (a -> m b) -> a -> m cSource

(=<<) :: (RMonad m, Suitable m a, Suitable m b) => (a -> m b) -> m a -> m bSource

(>=>) :: (RMonad m, Suitable m a, Suitable m b, Suitable m c) => (a -> m b) -> (b -> m c) -> a -> m cSource

ap :: (RMonad m, Suitable m (a -> b), Suitable m a, Suitable m b) => m (a -> b) -> m a -> m bSource

filterM :: (RMonad m, Suitable m [a], Suitable m Bool) => (a -> m Bool) -> [a] -> m [a]Source

foldM :: (RMonad m, Suitable m a) => (a -> b -> m a) -> a -> [b] -> m aSource

foldM_ :: (RMonad m, Suitable m a, Suitable m ()) => (a -> b -> m a) -> a -> [b] -> m ()Source

forM :: (RMonad m, Suitable m b, Suitable m [b]) => [a] -> (a -> m b) -> m [b]Source

forM_ :: (RMonad m, Suitable m b, Suitable m ()) => [a] -> (a -> m b) -> m ()Source

forever :: (RMonad m, Suitable m a, Suitable m b) => m a -> m bSource

guard :: (RMonadPlus m, Suitable m ()) => Bool -> m ()Source

join :: (RMonad m, Suitable m a, Suitable m (m a)) => m (m a) -> m aSource

liftM :: (RMonad m, Suitable m a1, Suitable m r) => (a1 -> r) -> m a1 -> m rSource

liftM2 :: (RMonad m, Suitable m a1, Suitable m a2, Suitable m r) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m rSource

liftM3 :: (RMonad m, Suitable m a1, Suitable m a2, Suitable m a3, Suitable m r) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m rSource

liftM4 :: (RMonad m, Suitable m a1, Suitable m a2, Suitable m a3, Suitable m a4, Suitable m r) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m rSource

liftM5 :: (RMonad m, Suitable m a1, Suitable m a2, Suitable m a3, Suitable m a4, Suitable m a5, Suitable m r) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m rSource

mapAndUnzipM :: (RMonad m, Suitable m (b, c), Suitable m [(b, c)], Suitable m ([b], [c])) => (a -> m (b, c)) -> [a] -> m ([b], [c])Source

mapM :: (RMonad m, Suitable m b, Suitable m [b]) => (a -> m b) -> [a] -> m [b]Source

mapM_ :: (RMonad m, Suitable m b, Suitable m ()) => (a -> m b) -> [a] -> m ()Source

msum :: (RMonadPlus m, Suitable m a) => [m a] -> m aSource

replicateM :: (RMonad m, Suitable m a, Suitable m [a]) => Int -> m a -> m [a]Source

replicateM_ :: (RMonad m, Suitable m a, Suitable m ()) => Int -> m a -> m ()Source

sequence :: (RMonad m, Suitable m a, Suitable m [a]) => [m a] -> m [a]Source

sequence_ :: (RMonad m, Suitable m a, Suitable m ()) => [m a] -> m ()Source

unless :: (RMonad m, Suitable m ()) => Bool -> m () -> m ()Source

when :: (RMonad m, Suitable m ()) => Bool -> m () -> m ()Source

zipWithM :: (RMonad m, Suitable m c, Suitable m [c]) => (a -> b -> m c) -> [a] -> [b] -> m [c]Source

zipWithM_ :: (RMonad m, Suitable m c, Suitable m ()) => (a -> b -> m c) -> [a] -> [b] -> m ()Source
{"ft_lang_label":"__label__en","ft_lang_prob":0.71350116,"math_prob":0.9139251,"size":3588,"snap":"2020-10-2020-16","text_gpt3_token_len":1110,"char_repetition_ratio":0.265625,"word_repetition_ratio":0.22720897,"special_character_ratio":0.33862877,"punctuation_ratio":0.14165498,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99340856,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-07T01:35:03Z\",\"WARC-Record-ID\":\"<urn:uuid:ff991162-a38b-4686-a6d3-eafb68bbde24>\",\"Content-Length\":\"26162\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:13562dfe-706b-4b34-ab43-355bd34c8114>\",\"WARC-Concurrent-To\":\"<urn:uuid:e03186fc-7c31-4ea7-9d20-6b00bdba9332>\",\"WARC-IP-Address\":\"151.101.248.68\",\"WARC-Target-URI\":\"https://hackage.haskell.org/package/rmonad-0.8.0.2/docs/Control-RMonad.html\",\"WARC-Payload-Digest\":\"sha1:TXAWNHW4QMCU57GLLV3KYPXVD3QK5BHE\",\"WARC-Block-Digest\":\"sha1:ZLNUBTQCVSIRFAWQW4E5BTQMYURQE2II\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585371662966.69_warc_CC-MAIN-20200406231617-20200407022117-00521.warc.gz\"}"}