[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to main content

Declarative Pearl: Rigged Contracts

  • Conference paper
Functional and Logic Programming (FLOPS 2024)

Abstract

Over 20 years ago, Peyton Jones et al. embarked on an adventure in financial engineering with their functional pearl on “Composing Contracts”. They introduced a combinator library—a domain-specific language—for precisely describing complex financial contracts and a formal denotational semantics for computing their value, for which they briefly sketched an implementation.

This paper reworks the design of their library to make the central datatype of contracts less ad-hoc by giving it a well-understood algebraic structure: the semiring. Then, interpreting a contract’s worth as a generic semiring homomorphism directly gives rise to a natural semantics for contracts, of which computing the (monetary) value is but one instance.

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

Access this chapter

Subscribe and save

Springer+ Basic
£29.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
GBP 19.95
Price includes VAT (United Kingdom)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
GBP 43.99
Price includes VAT (United Kingdom)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
GBP 54.99
Price includes VAT (United Kingdom)
  • 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.

    The meaning of the obs parameter is explained in Sect. 2.2.

  2. 2.

    Also called the acquisition date.

  3. 3.

    Backquotes turn a function into an infix operator, e.g., x ‘f’ y = f x y.

  4. 4.

    In reality, floating point numbers such as Double do violate semiring axioms due to rounding errors. Here, we stick with Doubles for simplicity.

  5. 5.

    give need not cancel out expired, since the annihilator of the semiring is excluded from the multiplicative group.

  6. 6.

    The partial inv is acceptable since the annihilator, NegInfty, need not be invertible.

  7. 7.

    For instance, their truncate epoch zero is not equal to our expired, because it can still be acquired at the epoch.

  8. 8.

    See the code repository for a gradient-based semantics.

References

  1. van den Berg, B., Schrijvers, T., McKinna, J., Vandenbroucke, A.: Forward- or reverse-mode automatic differentiation: what’s the difference? Sci. Comput. Program. 231, 103010 (2024)

    Article  Google Scholar 

  2. Elliott, C.: The simple essence of automatic differentiation. Proc. ACM Program. Lang. 2(ICFP), 70:1–70:29 (2018)

    Google Scholar 

  3. Erwig, M., Kollmansberger, S.: Functional pearls: probabilistic functional programming in Haskell. J. Funct. Program. 16(1), 21–34 (2006)

    Article  Google Scholar 

  4. Gibbons, J., Wu, N.: Folding domain-specific languages: deep and shallow embeddings (functional pearl). In: Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming. p. 339-347. ICFP ’14, Association for Computing Machinery, New York, NY, USA (2014). https://doi.org/10.1145/2628136.2628138

  5. Kozen, D.: Kleene algebra with tests. ACM Trans. Program. Lang. Syst. 19(3), 427–443 (1997)

    Article  Google Scholar 

  6. Peyton Jones, S.L., Eber, J., Seward, J.: Composing contracts: an adventure in financial engineering, functional pearl. In: ICFP. pp. 280–292. ACM (2000)

    Google Scholar 

  7. Rall, L.B.: Automatic Differentiation: Techniques and Applications. Lecture Notes in Computer Science, vol. 120. Springer, Heidelberg (1981). https://doi.org/10.1007/3-540-10861-0

    Book  Google Scholar 

  8. Yorgey, B.A.: Monoids: theme and variations (functional pearl). In: Haskell, pp. 105–116. ACM (2012)

    Google Scholar 

Download references

Acknowledgments

We are grateful for the helpful feedback of the anonymous reviewers. Part of this work was funded by FWO project 3E221387.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Tom Schrijvers .

Editor information

Editors and Affiliations

Ethics declarations

Disclosure of Interests

The authors have no competing interests.

Appendix: Deriving Expired

Appendix: Deriving Expired

Let us derive the implementation of expired from the semantics:

figure aq

The choice of zero for c in the derivation is immaterial; any contract would do. Moreover, there are other forms of contracts that behave like expired. For instance, (get zero) is also nil everywhere, because the getting a contract with an infinite expiry date is ill-defined, i.e., nil. The definition above is preferable because it relies only on the non-finance specific part of the semantics.

Rights and permissions

Reprints and permissions

Copyright information

© 2024 The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd.

About this paper

Cite this paper

Vandenbroucke, A., Schrijvers, T. (2024). Declarative Pearl: Rigged Contracts. In: Gibbons, J., Miller, D. (eds) Functional and Logic Programming. FLOPS 2024. Lecture Notes in Computer Science, vol 14659. Springer, Singapore. https://doi.org/10.1007/978-981-97-2300-3_6

Download citation

  • DOI: https://doi.org/10.1007/978-981-97-2300-3_6

  • Publisher Name: Springer, Singapore

  • Print ISBN: 978-981-97-2299-0

  • Online ISBN: 978-981-97-2300-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics