KIT | KIT-Bibliothek | Impressum | Datenschutz

‘do’ unchained: embracing local imperativity in a purely functional language (functional pearl)

Ullrich, Sebastian ORCID iD icon 1; de Moura, Leonardo
1 Institut für Programmstrukturen und Datenorganisation (IPD), Karlsruher Institut für Technologie (KIT)

Abstract:

Purely functional programming languages pride themselves with reifying effects that are implicit in imperative languages into reusable and composable abstractions such as monads. This reification allows for more exact control over effects as well as the introduction of new or derived effects. However, despite libraries of more and more powerful abstractions over effectful operations being developed, syntactically the common 'do' notation still lags behind equivalent imperative code it is supposed to mimic regarding verbosity and code duplication. In this paper, we explore extending 'do' notation with other imperative language features that can be added to simplify monadic code: local mutation, early return, and iteration. We present formal translation rules that compile these features back down to purely functional code, show that the generated code can still be reasoned over using an implementation of the translation in the Lean 4 theorem prover, and formally prove the correctness of the translation rules relative to a simple static and dynamic semantics in Lean.


Verlagsausgabe §
DOI: 10.5445/IR/1000151803
Veröffentlicht am 03.11.2022
Originalveröffentlichung
DOI: 10.1145/3547640
Scopus
Zitationen: 2
Dimensions
Zitationen: 1
Cover der Publikation
Zugehörige Institution(en) am KIT Institut für Programmstrukturen und Datenorganisation (IPD)
Publikationstyp Zeitschriftenaufsatz
Publikationsdatum 29.08.2022
Sprache Englisch
Identifikator ISSN: 2475-1421
KITopen-ID: 1000151803
Erschienen in Proceedings of the ACM on Programming Languages
Verlag Association for Computing Machinery (ACM)
Band 6
Heft ICFP
Seiten 512–539
Nachgewiesen in Dimensions
Scopus
KIT – Die Forschungsuniversität in der Helmholtz-Gemeinschaft
KITopen Landing Page