Skip to content

Latest commit

 

History

History
48 lines (30 loc) · 2.72 KB

Readme.md

File metadata and controls

48 lines (30 loc) · 2.72 KB

Hackage

Operational is a tiny library for implementing monads by specifying the primitive instructions and their operational semantics. The monad laws will hold automatically. It can also be used to define monad transformers where the lifting laws hold automatically.

Using operational semantics simplifies the implementation of monads with tricky control flow, such as:

  • web applications in sequential style
  • games with a uniform interface for human and AI players, and automatic replay
  • fast parser monads
  • monadic DSLs of any kind
  • ...

Any monad and monad transformer can be implemented in this fashion.

The library is based on the article The Operational Monad Tutorial, published in Issue 15 of The Monad.Reader.

Example

For example, imagine that you want to write a web application where the user is guided through a sequence of tasks ("wizard"). To structure your application, you can use a custom monad that supports an instruction askUserInput :: CustomMonad UserInput. This command sends a web form to the user and returns a result when he submits the form. However, you don't want your server to block while waiting for the user, so you have to suspend the computation and resume it at some later point. Sounds tricky to implement? This library makes it easy:

The idea is to identify a set of primitive instructions and to specify their operational semantics. Then, the library makes sure that the monad laws hold automatically. In the web application example, the primitive instruction would be AskUserInput.

The above example is implemented in WebSessionState.lhs.

Documentation

More documentation and examples are included in the doc/ folder.

Related

Sources and inspiration for this library include

Related packages included