Monadic Programming in Imperative Languages
dc.contributor.author | Anderlind, Joakim | |
dc.contributor.author | Åsberg, Mårten | |
dc.contributor.department | Chalmers tekniska högskola / Institutionen för data och informationsteknik | sv |
dc.contributor.department | Chalmers University of Technology / Department of Computer Science and Engineering | en |
dc.contributor.examiner | Adams, Robin | |
dc.contributor.supervisor | Myreen, Magnus | |
dc.date.accessioned | 2023-06-21T12:21:53Z | |
dc.date.available | 2023-06-21T12:21:53Z | |
dc.date.issued | 2023 | |
dc.date.submitted | 2023 | |
dc.description.abstract | Using monads as a generalised interface for abstracting computations has seen great success in functional languages such as Haskell. By generalising computations as monadic actions, one can use a specialised syntax, such as the do-notation of Haskell, to compose these actions into clearer programs. Although certain monadic features have been introduced into imperative languages, such as the various flatMap methods in Java or the try-operator in Rust, there is a lack of a generalised interface for composing monadic actions. The goal of this thesis is to investigate how monadic abstractions from functional languages can be transferred to imperative languages. To accomplish this, we present an interface for composing monadic actions that can be integrated within existing imperative languages. We begin with defining how our interface should be integrated within a host language while preserving the original semantics of said languages to as large a degree as possible. Then we develop an implementation of our interface in Rust via its procmacro system. Additionally, we developed a C# implementation of our interface for comparison. Finally, we benchmark the Rust implementation to analyse the potential performance cost of our interface. Using our Rust and C# implementations, we were able to integrate monads such as the Option, Writer, State, and List monads with minimal changes to existing syntax. Benchmarks shows that the interface itself introduces a noticeable performance cost compared to reference implementations without our interface. For future work, we suggest working on improvements of the usability and developer experience, that our interface may be implemented in other imperative languages, and that more research is needed into improving the performance of our interface. | |
dc.identifier.uri | http://hdl.handle.net/20.500.12380/306361 | |
dc.setspec.uppsok | Technology | |
dc.subject | monads | |
dc.subject | programming languages | |
dc.subject | language design | |
dc.subject | Rust | |
dc.subject | C# | |
dc.title | Monadic Programming in Imperative Languages | |
dc.type.degree | Examensarbete för masterexamen | sv |
dc.type.degree | Master's Thesis | en |
dc.type.uppsok | H | |
local.programme | Computer science – algorithms, languages and logic (MPALG), MSc |