Encoding Monadic Computations in C# Using Iterators.

Tomáš Petříček · 2009

Abstract. 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 for example to efficiently program multi-core pro-cessors 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 prob-lems. In this paper, we present a general way for encoding monadic computations in the C # 2.0 language with a conve-nient syntax using a specific language feature called itera-tors. 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. 1.

Read the paper · More papers on PaperTik