Tomas Petricek @ Computer Lab

Encoding monadic computations in C# using iterators

Tomas Petricek

In Proceedings of ITAT 2009

Many programming problems can be easily solved if we express them as computations with some non standard aspect. This is a very important problem, because today we’re struggling to efficiently program multi-core processors and to write asynchronous code. Unfortunately main-stream languages such as C# don’t support any direct way for encoding unrestricted non-standard computations. In languages like Haskell and F#, this can be done using monads with syntactic extensions they provide and it has been successfully applied to a wide range of real-world problems. In this paper, we present a general way for encoding monadic computations in the C# 2.0 language with a convenient syntax using a specific language feature called iterators. This gives us a way to use well-known non-standard computations enabling easy asynchronous programming or for example the use of software transactional memory in plain C#. Moreover, it also opens monads in general to a wider audience which can help in the search for other useful and previously unknown kinds of computations.

Paper and more information

Bibtex 

@inproceedings{iterators-itat09,
    author    = {Petricek, Tomas},
    title     = {Encoding monadic computations in C\# using iterators},
    booktitle = {Proceedings of the Conference on Theory and 
                 Practice of Information Technologies},
    series    = {ITAT 2009},
    location  = {Kralova studna, Slovakia},
} 

Comments are welcome!

If you have any comments, suggestions or related ideas, I'll be happy to hear from you at