Encoding monadic computations in C# using iterators
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 are struggling to efficiently program multi-core processors and to write asynchronous code. Unfortunately main-stream languages such as C# do not 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
- Download the paper (PDF) and supplementary materials (PDF)
- Look at the C# source code (ZIP)
- For more information read a related blog post
- View the slides from ITAT talk (PDF)
This paper contains a number of issues. Most importantly, it ignores the fact that C# 2.0 iterators keep mutable state, which makes running a continuation multiple times harder (as a result, it is only possible to easily encode one-shot continuations).
If you want to cite the paper, you can use the following BibTeX information, or get full details from the paper proceedings in CEUR-WS.
1: 2: 3: 4: 5: 6: 7: 8: 9:
Published: Monday, 1 June 2009, 12:00 AM
Author: Tomas Petricek
Typos: Send me pull request!