Evaluation strategies for monadic computations
Author:
Open Access
- 11 February 2012
- journal article
- Published by Open Publishing Association in Electronic Proceedings in Theoretical Computer Science
- Vol. 76, 68-89
Abstract
Monads have become a powerful tool for structuring effectful computations in functional programming, because they make the order of effects explicit. When translating pure code to a monadic version, we need to specify evaluation order explicitly. Two standard translations give call-by-value and call-by-name semantics. The resulting programs have different structure and types, which makes revisiting the choice difficult. In this paper, we translate pure code to monadic using an additional operation malias that abstracts out the evaluation strategy. The malias operation is based on computational comonads; we use a categorical framework to specify the laws that are required to hold about the operation. For any monad, we show implementations of malias that give call-by-value and call-by-name semantics. Although we do not give call-by-need semantics for all monads, we show how to turn certain monads into an extended monad with call-by-need semantics, which partly answers an open question. Moreover, using our unified translation, it is possible to change the evaluation strategy of functional code translated to the monadic form without changing its structure or types.Comment: In Proceedings MSFP 2012, arXiv:1202.240Keywords
All Related Versions
This publication has 22 references indexed in Scilit:
- A monad for deterministic parallelism2011
- Concurrent orchestration in Haskell2010
- Purely functional lazy non-deterministic programmingACM SIGPLAN Notices, 2009
- Call-By-Push-Value2003
- An operational semantics for parallel lazy evaluation2000
- Generalising monads to arrowsScience of Computer Programming, 2000
- The call-by-need lambda calculusJournal of Functional Programming, 1997
- State in HaskellHigher-Order and Symbolic Computation, 1995
- Monad transformers and modular interpreters1995
- A natural semantics for lazy evaluation1993