Abstract

Lazy evaluation is a powerful tool for functional programmers. It enables the concise expression of on-demand computation and a form of compositionality not available under other evaluation strategies. However, the stateful nature of lazy evaluation makes it hard to analyze a program's computational cost, either informally or formally. In this work, we present a novel and simple framework for formally reasoning about lazy computation costs based on a recent model of lazy evaluation: clairvoyant call-by-value. The key feature of our framework is its simplicity, as expressed by our definition of the clairvoyance monad. This monad is both simple to define (around 20 lines of Coq) and simple to reason about. We show that this monad can be effectively used to mechanically reason about the computational cost of lazy functional programs written in Coq.

Highlights

  • Lazy evaluation [Henderson and Morris 1976], or the call-by-need calling convention, is a distinguishing feature in some functional programming languagesÐHaskell being the most notable example

  • We present the clairvoyance monad, a model of laziness that can be shallowly embedded in Coq by distilling two core features of clairvoyant evaluation: nondeterminism and cost accumulation

  • Compared with the denotational semantics of Hackett and Hutton [2019], our translation deals with typed programs, does not rely on domain theory, and accounts for the cost of every nondeterministic execution (Section 4)

Read more

Summary

INTRODUCTION

Lazy evaluation [Henderson and Morris 1976], or the call-by-need calling convention, is a distinguishing feature in some functional programming languagesÐHaskell being the most notable example. Instead of storing the computations in a thunk, the clairvoyant call-by-value model makes use of nondeterminism to evaluate the data in one branch and skip evaluation in another. Our framework is based on an annotated model similar to that of Danielsson [2008] and of Handley et al [2020], but our work does not require an explicit notion of laziness to reason about computation costs under lazy evaluation. We present the clairvoyance monad, a model of laziness that can be shallowly embedded in Coq by distilling two core features of clairvoyant evaluation: nondeterminism and cost accumulation. We develop a translation from a lazy calculus to programs in this monad that captures the semantics of clairvoyant call-by-value evaluation. Below, we introduce our approach at a high level and present our running example

MOTIVATING EXAMPLE
Clairvoyant Evaluation
A Dual Reasoning Principle
The Missing Pieces
THE CLAIRVOYANCE MONAD
TRANSLATION
Formal Monadic Translation
Equivalence with Clairvoyant Call-By-Value
An Example
Simplifying Ticks
FORMAL REASONING
The Optimistic and Pessimistic Specifications
Reasoning Rules
Approximations
CASE STUDY
DISCUSSION
RELATED WORK
CONCLUSION AND FUTURE WORK
Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.