Difference between revisions of "Operational"

From HaskellWiki
Jump to navigation Jump to search
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== What is it? ==
 
== What is it? ==
   
  +
The ''operational'' library makes it easy to implement monads with tricky control flow.
''Operational'' is a small library for implementing custom monads.
 
   
  +
This is very useful for: writing web applications in a sequential style, programming games with a uniform interface for human and AI players and easy replay, implementing fast parser monads, designing monadic DSLs, etc.
The idea is that you can easily implement any monad by specifying instructions and their desired operational semantics.
 
  +
  +
For instance, 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 <code>askUserInput :: CustomMonad UserInput</code>. 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 <code>AskUserInput</code>.
  +
  +
Any monad can be implemented in this way. Ditto for monad transformers.
  +
  +
A thorough introduction to the ideas behind this library is given in [http://apfelmus.nfshost.com/articles/operational-monad.html "The Operational Monad Tutorial"], published in [http://themonadreader.wordpress.com/2010/01/26/issue-15/ Issue 15 of the Monad.Reader].
   
 
== Releases and Resources ==
 
== Releases and Resources ==
Line 12: Line 20:
 
* Documentation
 
* Documentation
 
** [http://themonadreader.wordpress.com/2010/01/26/issue-15/ The Operational Monad Tutorial] - Introductory document explaining the concept.
 
** [http://themonadreader.wordpress.com/2010/01/26/issue-15/ The Operational Monad Tutorial] - Introductory document explaining the concept.
** [http://projects.haskell.org/operational/Documentation.html Library documentation] - How to use the libary proper; documents changes with respect to the tutorial.
+
** [http://heinrichapfelmus.github.com/operational/Documentation.html Library documentation] - How to use the libary proper; documents changes with respect to the tutorial.
 
** [http://hackage.haskell.org/package/operational/ API reference] on hackage.
 
** [http://hackage.haskell.org/package/operational/ API reference] on hackage.
** '''[https://github.com/HeinrichApfelmus/operational/tree/master/doc/examples Example code]''' - Collection of working examples.
+
** '''[https://github.com/HeinrichApfelmus/operational/tree/master/doc/examples#readme Example code]''' - Collection of working examples.
 
* <span id="feedback">Feedback</span> and Contact
 
* <span id="feedback">Feedback</span> and Contact
 
** Maintainer: [http://apfelmus.nfshost.com/ Heinrich Apfelmus] <apfelmus at quantentunnel de>
 
** Maintainer: [http://apfelmus.nfshost.com/ Heinrich Apfelmus] <apfelmus at quantentunnel de>
Line 22: Line 30:
   
 
[[Category:Libraries]]
 
[[Category:Libraries]]
[[Category:Monads]]
+
[[Category:Monad]]
 
[[Category:Packages]]
 
[[Category:Packages]]

Revision as of 17:17, 18 June 2012

What is it?

The operational library makes it easy to implement monads with tricky control flow.

This is very useful for: writing web applications in a sequential style, programming games with a uniform interface for human and AI players and easy replay, implementing fast parser monads, designing monadic DSLs, etc.

For instance, 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.

Any monad can be implemented in this way. Ditto for monad transformers.

A thorough introduction to the ideas behind this library is given in "The Operational Monad Tutorial", published in Issue 15 of the Monad.Reader.

Releases and Resources