# Ticket #997 (closed proposal: fixed)

Opened 7 years ago

Reported by: Owned by: dons normal libraries/base 6.6 Unknown/Multiple Unknown/Multiple Easy (less than 1 hour)

### Description

Kleisli composition of monads is a foundational feature missing from the current Control.Monad library. A  recent discussion revealed solid support for its inclusion.

```    (>=>) :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
(<=<) :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
```

Along with the useful control combinator:

```    forever :: (Monad m) => m a -> m ()
```

Traditionally, >=> has been written as @@, however to support the flipped version, new notation seems to be required. It should be notated that there is overlap with the Kleisli class in Control.Arrow (specifically >>>), however, short of a convenient unifying form for Arrow and Monad, a monad-specific >>> seems reasonable. To mirror >>> and =<<, infixr 1 was chosen.

Proposal period: 2 weeks. Deadline: 27th November.

The patch in its entirety:

```New patches:

Don Stewart <dons@cse.unsw.edu.au>**20061113015442] {
+    , (>=>)         -- :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
+    , (<=<)         -- :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
+    , forever       -- :: (Monad m) => m a -> m ()
+infixr 1 <=<, >=>
+
+-- | Left-to-right Kleisli composition of monads.
+(>=>)       :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)
+f >=> g     = \x -> f x >>= g
+
+-- | Right-to-left Kleisli composition of monads. '(>=>)', with the arguments flipped
+(<=<)       :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c)
+(<=<)       = flip (>=>)
+
+-- | @'forever' act@ repeats the action infinitely.
+forever     :: (Monad m) => m a -> m ()
+forever a   = a >> forever a
+
+
```

## Change History

### Changed 6 years ago by igloo

• status changed from new to closed
• resolution set to fixed

Apparently uncontroversial; patch applied.

### Changed 5 years ago by simonmar

• architecture changed from Multiple to Unknown/Multiple

### Changed 5 years ago by simonmar

• os changed from Unknown to Unknown/Multiple

### Changed 4 years ago by simonmar

• difficulty changed from Easy (1 hr) to Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.