The F# Computation Expression Zoo

  • Tomas Petricek
  • Don Syme
Conference paper

DOI: 10.1007/978-3-319-04132-2_3

Part of the Lecture Notes in Computer Science book series (LNCS, volume 8324)
Cite this paper as:
Petricek T., Syme D. (2014) The F# Computation Expression Zoo. In: Flatt M., Guo HF. (eds) Practical Aspects of Declarative Languages. PADL 2014. Lecture Notes in Computer Science, vol 8324. Springer, Cham

Abstract

Program logic can often be structured using abstract computation types such as monoids, monad transformers or applicative functors. Functional programmers use those abstractions directly while main-stream languages often integrate concrete instances as language features – e.g. generators in Python or asynchronous computations in C# 5.0. The question is, is there a sweet spot between convenient, hardwired language features, and an inconvenient but flexible libraries?

F# computation expressions answer this question in the affirmative. Unlike the “do” notation in Haskell, computation expressions are not tied to a single kind of abstraction. They support a wide range of abstractions, depending on what operations are available. F# also provides greater syntactic flexibility leading to a more intuitive syntax, without resorting to full macro-based meta-programming.

We present computation expressions in a principled way, developing a type system that captures the semantics of the calculus. We demonstrate how computation expressions structure well-known abstractions including monoidal list comprehensions, monadic parsers, applicative formlets and asynchronous sequences based on monad transformers.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Tomas Petricek
    • 1
  • Don Syme
    • 2
  1. 1.University of CambridgeUK
  2. 2.Microsoft Research CambridgeUK

Personalised recommendations