ekmett/free — pull request #30 by fizruk (2013-11-13 09:10:31+00:00)
Title: makeFree - automatic generation of free monadic actions

For previous discussion see #29.

The current implementation works with this:

```haskell
data Lang next
= Done
| Failure String
| Output String next
| Input (String -> next)
| InputWithNo (Int -> String -> next)
| Fork next (Int -> next)
| AnyOf (Int -> Int -> Int -> next) (String -> next)
deriving (Functor)
makeFree ''Lang
```

This results in the following functions:

```haskell
done :: MonadFree Lang m => m a
done = liftF Done

failure :: MonadFree Lang m => String -> m a
failure s = liftF (Failure s)

output :: MonadFree Lang m => String -> m ()
output s = liftF (Output s ())

input :: MonadFree Lang m => m String
input = liftF (Input id)

inputWithNo :: MonadFree Lang m => m (Int, String)
inputWithNo = liftF (InputWithNo (\x y -> (x, y)))

fork :: MonadFree Lang m => m (Maybe Int)
fork = liftF (Fork Nothing (\x -> Just x))

anyOf :: MonadFree Lang m => m (Either (Int, Int, Int) String)
anyOf = liftF (AnyOf (\x y z -> Left (x, y, z)) (\s -> Right s))
```