Skip to main content
Erschienen in: Journal of Automated Reasoning 2/2019

10.07.2018

Effect Polymorphism in Higher-Order Logic (Proof Pearl)

verfasst von: Andreas Lochbihler

Erschienen in: Journal of Automated Reasoning | Ausgabe 2/2019

Einloggen

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

The notion of a monad cannot be expressed within higher-order logic (HOL) due to type system restrictions. I show that if a monad is restricted to values of a fixed type, this notion can be formalised in HOL. Based on this idea, I develop a library of effect specifications and implementations of monads and monad transformers. Hence, I can abstract over the concrete monad in HOL definitions and thus use the same definition for different (combinations of) effects. I illustrate the usefulness of effect polymorphism with a monadic interpreter.

Sie haben noch keine Lizenz? Dann Informieren Sie sich jetzt über unsere Produkte:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Anhänge
Nur mit Berechtigung zugänglich
Fußnoten
2
Type variables that appear in the signature of locale parameters are fixed for the whole locale. In particular, the value type https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figaw_HTML.gif cannot be instantiated inside the locale https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figax_HTML.gif or its extension https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figay_HTML.gif . The interpreter https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figaz_HTML.gif , however, returns https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figba_HTML.gif s. For this reason, https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figbb_HTML.gif is defined in an extension of https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figbc_HTML.gif that merely specialises https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figbd_HTML.gif to https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figbe_HTML.gif . For readability, I usually omit this detail in this article.
 
3
Continuation parameters like https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figdc_HTML.gif ’s and https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figdd_HTML.gif ’s make it possible to circumvent the restriction to monomorphic values. More generally, if we made every definition take a continuation, like in continuation-passing style, we would regain value polymorphism. In doing so, we would however lose that sequencing of computations and control flow is captured by a small number of (primitive) operations. Instead, every definition could implement arbitrary control flow, like in a continuation monad. Thus, we would need a lot more lemmas to reason about sequencing. In a commutative monad, e.g., one commutativity lemma would be needed for every pair of definitions. In contrast, my approach needs just one assumption comm to express commutativity of sequencing (Sect. 2.5), and a few assumptions about the primitive operations, e.g., sample-comm (Sect. 2.3).
 
4
In my monad implementations in Sect. 3, sampling is relationally parametric for arbitrary relations https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figeu_HTML.gif , so I could drop the restriction https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figev_HTML.gif . However, this would unnecessarily exclude some other implementations as all my abstract proofs so far used only https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figew_HTML.gif relations.
 
5
The support of https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figfz_HTML.gif is the set of elementary events with positive probability: https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figga_HTML.gif iff https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figgb_HTML.gif
 
6
The conference paper [23] demanded sample-cong instead of sample-param. Parametricity is a better condition as it allows us to rename choices like in the biased coin flip example above.
 
7
Such environments can be nicely handled by adding a reader monad transformer (Sect. 4).
 
8
Isabelle’s https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figti_HTML.gif feature, which resolves overloading during type checking, cannot be used either as it does not support recursive resolutions. For example, resolving https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figtj_HTML.gif takes two steps: first to https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figtk_HTML.gif and then to https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figtl_HTML.gif . The second step fails due to the intricate interleaving of type checking and resolution. Even if this is just an implementation issue, resolving overloading during type checking prevents definitions that are generic in the monad, which general overloading supports.
 
9
Following the “as abstract as possible” spirit of this paper, I actually proved the identities in the locale of commutative monads and showed that https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figyd_HTML.gif is commutative if its inner monad is.
 
10
The alternative applicative interface [16] with the operator https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figys_HTML.gif is amenable to monomorphisation if we restrict ourselves to infinite value types https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figyt_HTML.gif as then https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figyu_HTML.gif is isomorphic to https://static-content.springer.com/image/art%3A10.1007%2Fs10817-018-9476-2/MediaObjects/10817_2018_9476_Figyv_HTML.gif . This interface is tailored towards a first-order language [10]. So functions must be uncurried and their arguments encoded using the isomorphism. We would thus clutter the definitions and proofs with conversions and lose the benefits of built-in higher-order unification.
 
Literatur
1.
Zurück zum Zitat Back, R.J., Wright, J.: Refinement Calculus—A Systematic Introduction. Springer, Berlin (1998)CrossRefMATH Back, R.J., Wright, J.: Refinement Calculus—A Systematic Introduction. Springer, Berlin (1998)CrossRefMATH
3.
Zurück zum Zitat Blanchette, J.C., Hölzl, J., Lochbihler, A., Panny, L., Popescu, A., Traytel, D.: Truly modular (co)datatypes for Isabelle/HOL. In: ITP 2014. LNCS, vol. 8558, pp. 93–110. Springer (2014) Blanchette, J.C., Hölzl, J., Lochbihler, A., Panny, L., Popescu, A., Traytel, D.: Truly modular (co)datatypes for Isabelle/HOL. In: ITP 2014. LNCS, vol. 8558, pp. 93–110. Springer (2014)
8.
Zurück zum Zitat Grimm, N., Maillard, K., Fournet, C., Hriţcu, C., Maffei, M., Protzenko, J., Ramananandro, T., Rastogi, A., Swamy, N., Zanella Béguelin, S.: A monadic framework for relational verification: applied to information security, program equivalence, and optimizations. In: CPP 2018, pp. 130–145. ACM (2018). https://doi.org/10.1145/3167090 Grimm, N., Maillard, K., Fournet, C., Hriţcu, C., Maffei, M., Protzenko, J., Ramananandro, T., Rastogi, A., Swamy, N., Zanella Béguelin, S.: A monadic framework for relational verification: applied to information security, program equivalence, and optimizations. In: CPP 2018, pp. 130–145. ACM (2018). https://​doi.​org/​10.​1145/​3167090
26.
Zurück zum Zitat Moggi, E.: An abstract view of programming languages. Technical report ECS-LFCS-90-113, LFCS, School of Informatics, University of Edinburgh (1990) Moggi, E.: An abstract view of programming languages. Technical report ECS-LFCS-90-113, LFCS, School of Informatics, University of Edinburgh (1990)
28.
Zurück zum Zitat Nipkow, T., Paulson, L.C.: Proof pearl: defining functions over finite sets. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 385–396. Springer (2005) Nipkow, T., Paulson, L.C.: Proof pearl: defining functions over finite sets. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 385–396. Springer (2005)
31.
Zurück zum Zitat Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: IFIP 1983. Information Processing, vol. 83, pp. 513–523. North-Holland/IFIP (1983) Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: IFIP 1983. Information Processing, vol. 83, pp. 513–523. North-Holland/IFIP (1983)
33.
Zurück zum Zitat Wadler, P.: How to replace failure by a list of successes: a method for exception handling, backtracking, and pattern matching in lazy functional languages. In: Jouannaud, J.P. (ed.) Functional Programming Languages and Computer Architecture (FPCA 1985). LNCS, vol. 201, pp. 113–128. Springer (1985). https://doi.org/10.1007/3-540-15975-4_33 Wadler, P.: How to replace failure by a list of successes: a method for exception handling, backtracking, and pattern matching in lazy functional languages. In: Jouannaud, J.P. (ed.) Functional Programming Languages and Computer Architecture (FPCA 1985). LNCS, vol. 201, pp. 113–128. Springer (1985). https://​doi.​org/​10.​1007/​3-540-15975-4_​33
36.
Zurück zum Zitat Wimmer, S., Hu, S., Nipkow, T.: Verified memoization and dynamic programming. In: Avigad, J., Mahboubi, A. (eds.) Interactive theorem proving. ITP 2018. LNCS, vol. 10895, pp. 579–596. Springer, Cham (2018) Wimmer, S., Hu, S., Nipkow, T.: Verified memoization and dynamic programming. In: Avigad, J., Mahboubi, A. (eds.) Interactive theorem proving. ITP 2018. LNCS, vol. 10895, pp. 579–596. Springer, Cham (2018)
Metadaten
Titel
Effect Polymorphism in Higher-Order Logic (Proof Pearl)
verfasst von
Andreas Lochbihler
Publikationsdatum
10.07.2018
Verlag
Springer Netherlands
Erschienen in
Journal of Automated Reasoning / Ausgabe 2/2019
Print ISSN: 0168-7433
Elektronische ISSN: 1573-0670
DOI
https://doi.org/10.1007/s10817-018-9476-2

Weitere Artikel der Ausgabe 2/2019

Journal of Automated Reasoning 2/2019 Zur Ausgabe