Skip to main content

The F# Computation Expression Zoo

  • Conference paper
Book cover Practical Aspects of Declarative Languages (PADL 2014)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8324))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Bierman, G., Russo, C., Mainland, G., Meijer, E., Torgersen, M.: Pause ’n’ play: formalizing asynchronous C\(^\sharp\). In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 233–257. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  2. Cooper, E., Lindley, S., Wadler, P., Yallop, J.: The essence of form abstraction. In: Ramalingam, G. (ed.) APLAS 2008. LNCS, vol. 5356, pp. 205–220. Springer, Heidelberg (2008)

    Chapter  Google Scholar 

  3. Filinski, A.: Representing layered monads. In: POPL, pp. 175–188 (1999)

    Google Scholar 

  4. Filinski, A.: Monads in action. In: POPL, pp. 483–494 (2010)

    Google Scholar 

  5. Giorgidze, G., Grust, T., Schweinsberg, N., Weijers, J.: Bringing back monad comprehensions. In: Haskell Symposium, pp. 13–22 (2011)

    Google Scholar 

  6. Harris, T., Marlow, S., Peyton-Jones, S., Herlihy, M.: Composable memory transactions. In: PPoPP, pp. 48–60 (2005)

    Google Scholar 

  7. HaskellWiki. Listt done right (2012), http://www.haskell.org/haskellwiki/ListT_done_right

  8. HaskellWiki. Monadplus (2012), http://www.haskell.org/haskellwiki/MonadPlus

  9. Krishnamurthi, S.: Artifact evaluation for software conferences (2012), http://cs.brown.edu/~sk/Memos/Conference-Artifact-Evaluation/

  10. Liang, S., Hudak, P., Jones, M.: Monad transformers and modular interpreters. In: POPL (1995)

    Google Scholar 

  11. Lindley, S., Wadler, P., Yallop, J.: Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electron. Notes Theor. Comput. Sci. 229(5) (March 2011)

    Google Scholar 

  12. Lüth, C., Ghani, N.: Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, ICFP, pp. 133–144 (2002)

    Google Scholar 

  13. Mcbride, C., Paterson, R.: Applicative programming with effects. J. Funct. Program. 18(1), 1–13 (2008)

    Article  MATH  Google Scholar 

  14. Meijer, E., Beckman, B., Bierman, G.: LINQ: reconciling object, relations and XML in the.NET framework. In: SIGMOD, p. 706 (2006)

    Google Scholar 

  15. Paterson, R.: A new notation for arrows. In: ICFP (2001)

    Google Scholar 

  16. Petricek, T.: Programming with F# asynchronous sequences (2011), http://tomasp.net/blog/async-sequences.aspx

  17. Plotkin, G., Pretnar, M.: Handlers of algebraic effects. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 80–94. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  18. Rompf, T., Maier, I., Odersky, M.: Implementing first-class polymorphic delimited continuations by a type-directed selective cps-transform. In: ICFP (2009)

    Google Scholar 

  19. Syme, D., Petricek, T., Lomov, D.: The F# asynchronous programming model. In: Rocha, R., Launchbury, J. (eds.) PADL 2011. LNCS, vol. 6539, pp. 175–189. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  20. The F# Software Foundation. F# language specification (2013)

    Google Scholar 

  21. Typesafe Inc. An asynchronous programming facility for scala (2013)

    Google Scholar 

  22. Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Springer International Publishing Switzerland

About this paper

Cite this paper

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. https://doi.org/10.1007/978-3-319-04132-2_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-04132-2_3

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-04131-5

  • Online ISBN: 978-3-319-04132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics