Skip to main content

Double Applicative Functors

  • Conference paper
  • First Online:
Book cover Theoretical Aspects of Computing – ICTAC 2018 (ICTAC 2018)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 11187))

Included in the following conference series:

Abstract

Writing easily readable parser code is a classic application of monads in functional programming. For simpler cases, the Applicative and Alternative type classes in Haskell can be used for this purpose instead of the more powerful Monad and MonadPlus classes. Counterparts of all parsing expression grammar constructs except lookaheads are expressible via the Applicative and Alternative class methods. Yet their error handling capabilities are unsatisfactory even for simple applications. This paper proposes double applicative functors for increasing the flexibility of error handling without full monadic power, along with an extended set of operations, and studies relationships between mathematical laws that these operations are assumed to fulfill. Many properties of these operations are generalizations of semantic equivalences previously known for parsing expression grammars.

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 69.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 89.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

Notes

  1. 1.

    Not to be confused with the standard notion of idempotent monads defined as those whose multiplication is an isomorphism.

  2. 2.

    For similar reasons, of [1] is not a monad morphism though is (the paper incorrectly claims both to be monad morphisms).

References

  1. Ahman, D., Uustalu, T.: Update monads: cointerpreting directed containers. In: Matthes, R., Schubert, A. (eds.) 19th International Conference on Types for Proofs and Programs, TYPES 2013. Leibniz International Proceedings in Informatics, Toulouse, April 2013, vol. 26, pp. 1–23. Dagstuhl Publishing, Saarbrücken/Wadern (2014). https://doi.org/10.4230/lipics.types.2013.1

  2. Aho, A.V., Ullman, J.D.: The Theory of Parsing, Translation, and Compiling. 1: Parsing. Prentice-Hall, Englewood Cliffs (1972)

    Google Scholar 

  3. Bifunctors and biapplicatives. https://github.com/purescript/purescript-bifunctors

  4. Birman, A., Ullman, J.D.: Parsing algorithms with backtrack. Inf. Control 23(1), 1–34 (1973). https://doi.org/10.1016/s0019-9958(73)90851-6

    Article  MathSciNet  MATH  Google Scholar 

  5. Cockett, J.R.B., Lack, S.: Restriction categories III: colimits, partial limits and extensivity. Math. Struct. Comput. Sci. 17(4), 775–817 (2007). https://doi.org/10.1017/s0960129507006056

    Article  MathSciNet  MATH  Google Scholar 

  6. Danielsson, N.A., Hughes, J., Jansson, P., Gibbons, J.: Fast and loose reasoning is morally correct. In: Proceedings of 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2006, Charleston, SC, pp. 206–217. ACM Press, New York (2006). https://doi.org/10.1145/1111037.1111056

  7. Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. In: Proceedings of 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2004, Venice, January 2004, pp. 111–122. ACM Press, New York (2004). https://doi.org/10.1145/964001.964011

  8. Haskell. https://www.haskell.org

  9. Haskell hierarchical libraries. https://downloads.haskell.org/~ghc/latest/docs/html/libraries/index.html

  10. Hinze, R.: Lifting operators and laws (2010). https://www.cs.ox.ac.uk/ralf.hinze/Lifting.pdf

  11. King, D.J., Wadler, P.: Combining monads. In: Launchbury, J., Sansom, P.M. (eds.) Functional Programming, Glasgow 1992. Workshops in Computing, pp. 134–143. Springer, London (1993). https://doi.org/10.1007/978-1-4471-3215-8_12

    Chapter  Google Scholar 

  12. Kmett, E.: Biapplicative bifunctors. https://hackage.haskell.org/package/bifunctors-3.2.0.1/docs/Data-Biapplicative.html

  13. Liang, S., Hudak, P., Jones, M.P.: Monad transformers and modular interpreters. In: Conference Record of 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1995, San Francisco, CA, January 1995, pp. 333–343. ACM Press, New York (1995). https://doi.org/10.1145/199448.199528

  14. Lindley, S.: Algebraic effects and effect handlers for idioms and arrows. In: Proceedings of 10th ACM SIGPLAN Workshop on Generic Programming, WGP 2014, Gothenburg, August 2014, pp. 47–58. ACM Press, New York (2014). https://doi.org/10.1145/2633628.2633636

  15. Lindley, S., Wadler, P., Yallop, J.: Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electron. Notes Theor. Comput. Sci. 229(5), 97–117 (2011). https://doi.org/10.1016/j.entcs.2011.02.018

    Article  MathSciNet  MATH  Google Scholar 

  16. Maidl, A.M., Mascarenhas, F., Medeiros, S., Ierusalimschy, R.: Error reporting in parsing expression grammars. Sci. Comput. Program. 132, 129–140 (2016). https://doi.org/10.1016/j.scico.2016.08.004

    Article  MATH  Google Scholar 

  17. McBride, C., Paterson, R.: Applicative programming with effects. J. Funct. Program. 18(1), 1–13 (2008). https://doi.org/10.1017/s0956796807006326

    Article  MATH  Google Scholar 

  18. Mizushima, K., Maeda, A., Yamaguchi, Y.: Packrat parsers can handle practical grammars in mostly constant space. In: Proceedings of 9th ACM SIGPLAN-SIGSOFT Workshop on Program Analysis for Software Tools and Engineering, PASTE 2010, Toronto, ON, June 2010, pp. 29–36. ACM Press, New York (2010). https://doi.org/10.1145/1806672.1806679

  19. Moggi, E.: An abstract view of programming languages. Technical report, ECS-LFCS-90-113, University of Edinburgh (1990)

    Google Scholar 

  20. Röjemo, N.: Highlights from nhc–a space-efficient Haskell compiler. In: Proceedings of 7th International Conference on Functional Programming Languages and Computer Architecture, FPCA 1995, La Jolla, CA, June 1995, pp. 282–292. ACM Press (1995). https://doi.org/10.1145/224164.224217

  21. Swierstra, S.D.: Combinator parsing: a short tutorial. In: Bove, A., Barbosa, L.S., Pardo, A., Pinto, J.S. (eds.) LerNet 2008. LNCS, vol. 5520, pp. 252–300. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03153-3_6

    Chapter  Google Scholar 

  22. Swierstra, S.D., Duponcheel, L.: Deterministic, error-correcting combinator parsers. In: Launchbury, J., Meijer, E., Sheard, T. (eds.) AFP 1996. LNCS, vol. 1129, pp. 184–207. Springer, Heidelberg (1996). https://doi.org/10.1007/3-540-61628-4_7

    Chapter  Google Scholar 

  23. Uustalu, T., Veltri, N.: The delay monad and restriction categories. In: Hung, D.V., Kapur, D. (eds.) ICTAC 2017. LNCS, vol. 10580, pp. 32–50. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-67729-3_3

    Chapter  Google Scholar 

  24. Uustalu, T., Veltri, N.: Partiality and container monads. In: Chang, B.-Y.E. (ed.) APLAS 2017. LNCS, vol. 10695, pp. 406–425. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-71237-6_20

    Chapter  MATH  Google Scholar 

  25. Wadler, P.: Comprehending monads. Math. Struct. Comput. Sci. 2(4), 461–493 (1992). https://doi.org/10.1017/s0960129500001560

    Article  MathSciNet  MATH  Google Scholar 

Download references

Acknowledgement

The work was partially supported by the Estonian Research Council under R&D project No. IUT2-1.

The author thanks Tarmo Uustalu for fruitful discussions and also the anonymous reviewers for valuable feedback.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Härmel Nestra .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Nestra, H. (2018). Double Applicative Functors. In: Fischer, B., Uustalu, T. (eds) Theoretical Aspects of Computing – ICTAC 2018. ICTAC 2018. Lecture Notes in Computer Science(), vol 11187. Springer, Cham. https://doi.org/10.1007/978-3-030-02508-3_18

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-02508-3_18

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-02507-6

  • Online ISBN: 978-3-030-02508-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics