skip to main content
research-article
Open access

Selective applicative functors

Published: 26 July 2019 Publication History

Abstract

Applicative functors and monads have conquered the world of functional programming by providing general and powerful ways of describing effectful computations using pure functions. Applicative functors provide a way to compose independent effects that cannot depend on values produced by earlier computations, and all of which are declared statically. Monads extend the applicative interface by making it possible to compose dependent effects, where the value computed by one effect determines all subsequent effects, dynamically.
This paper introduces an intermediate abstraction called selective applicative functors that requires all effects to be declared statically, but provides a way to select which of the effects to execute dynamically. We demonstrate applications of the new abstraction on several examples, including two industrial case studies.

Supplementary Material

WEBM File (a90-mokhov.webm)

References

[1]
Nick Benton and Andrew Kennedy. 2001. Exceptional syntax. Journal of Functional Programming 11, 4 (2001), 395–410.
[2]
Yves Bertot and Pierre Castéran. 2013. Interactive theorem proving and program development: Coq’Art: the calculus of inductive constructions. Springer Science & Business Media.
[3]
Chris Birchall and Hamish Dickson. 2019. Implementation of selective applicative functors in Scala. (2019). https://web.archive.org/web/20190623214126/https://github.com/cb372/cats- selective/blob/master/core/src/main/ scala/cats/Selective.scala .
[4]
Baldur Blöndal, Andres Löh, and Ryan Scott. 2018. Deriving Via. In Proceedings of the 11th ACM Haskell Symposium (Haskell’18).
[5]
Paolo Capriotti and Ambrus Kaposi. 2014. Free applicative functors. Proceedings 5th Workshop on Mathematically Structured Functional Programming 153, 2–30.
[6]
Jack B Dennis and David P Misunas. 1975. A preliminary architecture for a basic data-flow processor. In ACM SIGARCH Computer Architecture News, Vol. 3. ACM, 126–132.
[7]
Dominique Devriese, Ilya Sergey, Dave Clarke, and Frank Piessens. 2013. Fixing idioms: a recursion primitive for applicative DSLs. In Proceedings of the ACM SIGPLAN 2013 workshop on Partial evaluation and program manipulation. ACM, 97–106.
[8]
Will Fancher. 2016. More on Applicative Effects in Free Monads. (2016). https://web.archive.org/web/20190307232337/https: //elvishjerricco.github.io/2016/04/13/more- on- applicative- effects- in- free- monads.html .
[9]
Will Fancher. 2017. Profunctors, Arrows, & Static Analysis. (2017). https://web.archive.org/web/20190307232429/https: //elvishjerricco.github.io/2017/03/10/profunctors- arrows- and- static- analysis.html .
[10]
Jeremy Gibbons. 2016. Free delivery (functional pearl). In ACM SIGPLAN Notices, Vol. 51. ACM, 45–50.
[11]
Richard Gibson. 2019. Implementation of selective applicative functors in Kotlin. (2019). https://web. archive.org/web/20190623213927/https://github.com/arrow- kt/arrow/blob/master/modules/core/arrow- coredata/src/main/kotlin/arrow/typeclasses/Selective.kt .
[12]
Andy Gill, Neil Sculthorpe, Justin Dawson, Aleksander Eskilson, Andrew Farmer, Mark Grebe, Jeffrey Rosenbluth, Ryan Scott, and James Stanton. 2015. The remote monad design pattern. In ACM SIGPLAN Notices, Vol. 50. ACM, 59–70.
[13]
Robert Harper. 2011. Boolean Blindness. (2011). https://web.archive.org/web/20110321191234/http://existentialtype. wordpress.com/2011/03/15/boolean- blindness/ .
[14]
Antti Holvikari. 2018. Implementation of selective applicative functors in PureScript. (2018). https://web.archive.org/web/ 20190623214040/https://github.com/anttih/purescript- selective/blob/master/src/Control/Selective.purs .
[15]
John Hughes. 2000. Generalising monads to arrows. Science of computer programming 37, 1-3 (2000), 67–111.
[16]
Graham Hutton and Erik Meijer. 1998. Monadic parsing in Haskell. Journal of functional programming 8, 4 (1998), 437–444.
[17]
Jane Street. 2015. Incremental: A library for incremental computations. Bind, scopes, and invalidation. (2015). https://web.archive.org/web/20190709231158/https://ocaml.janestreet.com/ocaml- core/latest/doc/incremental/ Incremental__/Incremental_intf/#bind, - scopes, - and- invalidation .
[18]
Jane Street. 2018. Dune: A composable build system. (2018). https://dune.build/ .
[19]
Oleg Kiselyov and Hiromi Ishii. 2015. Freer Monads, More Extensible Effects. SIGPLAN Not. 50, 12 (Aug. 2015), 94–105.
[20]
Daan Leijen and Erik Meijer. 2000. Domain specific embedded compilers. ACM Sigplan Notices 35, 1 (2000), 109–122.
[21]
Sam Lindley, Philip Wadler, and Jeremy Yallop. 2011. Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electronic notes in theoretical computer science 229, 5 (2011), 97–117.
[22]
Georgy Lukyanov. 2019. Implementation of selective applicative functors in Coq. (2019). https://web.archive.org/web/ 20190623213821/https://github.com/tuura/selective- theory- coq/blob/master/src/Control/Selective.v .
[23]
Simon Marlow, Louis Brandy, Jonathan Coens, and Jon Purdy. 2014. There is no fork: An abstraction for efficient, concurrent, and concise data access. In ACM SIGPLAN Notices, Vol. 49. ACM, 325–337.
[24]
Simon Marlow, Simon Peyton Jones, Edward Kmett, and Andrey Mokhov. 2016. Desugaring Haskell’s do-notation into applicative operations. In ACM SIGPLAN Notices, Vol. 51. ACM, 92–104.
[25]
Conor McBride and Ross Paterson. 2008. Applicative programming with effects. Journal of Functional Programming 18, 1 (2008), 1–13.
[26]
Adam Megacz. 2011. Hardware design with generalized arrows. In International Symposium on Implementation and Application of Functional Languages. Springer, 164–180.
[27]
Dave Menendez. 2013. Free Applicative Functors in Haskell. (2013). https://web.archive.org/web/20190625202450/https: //www.eyrie.org/~zednenem/2013/05/27/freeapp .
[28]
Eugenio Moggi. 1991. Notions of computation and monads. Information and computation 93, 1 (1991), 55–92.
[29]
Andrey Mokhov. 2009. Conditional partial order graphs. Ph.D. Dissertation. Newcastle University.
[30]
Andrey Mokhov. 2018. Selective applicative functors (blog post). (2018). https://web.archive.org/web/20190501160729/https: //blogs.ncl.ac.uk/andreymokhov/selective/ .
[31]
Andrey Mokhov. 2019. Implementation of selective applicative functors in Haskell. (2019). https://hackage.haskell.org/ package/selective .
[32]
Andrey Mokhov, Neil Mitchell, and Simon Peyton Jones. 2018. Build Systems à la Carte. Proceedings of the ACM on Programming Languages 2, ICFP (2018), 79.
[33]
Ross Paterson. 2001. A new notation for arrows. In ACM SIGPLAN Notices, Vol. 36. ACM, 229–240.
[34]
Daniel Peebles. 2019. Sigma Selective. (2019). http://web.archive.org/web/20190625225137/https://gist.github.com/ copumpkin/d5bdbc7afda54ff04049b6bdbcffb67e .
[35]
Evgeny Permyakov et al. 2012. Applicative functors with branch/choice. (2012). https://web.archive.org/web/20190626004303/ https://mail.haskell.org/pipermail/haskell- cafe/2012- July/102518.html .
[36]
Matthew Pickering, Jeremy Gibbons, and Nicolas Wu. 2017. Profunctor optics: Modular data accessors. Art, Science, and Engineering of Programming 1, 2 (2017).
[37]
Exequiel Rivas and Mauro Jaskelioff. 2017. Notions of computation as monoids. Journal of functional programming 27 (2017).
[38]
Tomás Ruiz-López. 2019. Implementation of selective applicative functors in Swift. (2019). https://web.archive.org/save/https: //github.com/bow- swift/bow/blob/master/Sources/Bow/Typeclasses/Selective.swift .
[39]
Colin Runciman, Matthew Naylor, and Fredrik Lindblad. 2008. SmallCheck and Lazy SmallCheck: automatic exhaustive testing for small values. In Acm sigplan notices, Vol. 44. ACM, 37–48.
[40]
Danil Sokolov, Alessandro de Gennaro, and Andrey Mokhov. 2018. Reconfigurable asynchronous pipelines: From formal models to silicon. In 2018 Design, Automation & Test in Europe Conference & Exhibition (DATE). IEEE, 1562–1567.
[41]
S Doaitse Swierstra and Luc Duponcheel. 1996. Deterministic, error-correcting combinator parsers. In International School on Advanced Functional Programming. Springer, 184–207.
[42]
Wouter Swierstra. 2008. Data types à la carte. Journal of functional programming 18, 4 (2008), 423–436.
[43]
The OPAM team. 2018. OCaml Package Manager. (2018). https://opam.ocaml.org/ .
[44]
Philip Wadler. 1989. Theorems for free!. In FPCA, Vol. 89. 347–359.
[45]
P. Wadler. 1995. Monads for functional programming. In Int’l School on Advanced Functional Programming. Springer, 24–52.
[46]
Jeremy Yallop. 2010. Abstraction for web programming. Ph.D. Dissertation. The University of Edinburgh.
[47]
Brent Yorgey et al. 2009. An IRC conversation about Branchy type class. (2009). https://web.archive.org/web/20190626003950/ https://github.com/snowleopard/selective/blob/master/paper/irc- log- branchy.md .

Cited By

View all

Index Terms

  1. Selective applicative functors

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image Proceedings of the ACM on Programming Languages
      Proceedings of the ACM on Programming Languages  Volume 3, Issue ICFP
      August 2019
      1054 pages
      EISSN:2475-1421
      DOI:10.1145/3352468
      Issue’s Table of Contents
      Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third-party components of this work must be honored. For all other uses, contact the Owner/Author.

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 26 July 2019
      Published in PACMPL Volume 3, Issue ICFP

      Check for updates

      Badges

      Author Tags

      1. applicative functors
      2. effects
      3. monads
      4. selective functors

      Qualifiers

      • Research-article

      Funding Sources

      • Royal Society

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)560
      • Downloads (Last 6 weeks)74
      Reflects downloads up to 01 Jan 2025

      Other Metrics

      Citations

      Cited By

      View all

      View Options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Login options

      Full Access

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media