Journal of Automated Reasoning

, Volume 59, Issue 1, pp 87–120

Type-Based Cost Analysis for Lazy Functional Languages

  • Steffen Jost
  • Pedro Vasconcelos
  • Mário Florido
  • Kevin Hammond

DOI: 10.1007/s10817-016-9398-9

Cite this article as:
Jost, S., Vasconcelos, P., Florido, M. et al. J Autom Reasoning (2017) 59: 87. doi:10.1007/s10817-016-9398-9


We present a static analysis for determining the execution costs of lazily evaluated functional languages, such as Haskell. Time- and space-behaviour of lazy functional languages can be hard to predict, creating a significant barrier to their broader acceptance. This paper applies a type-based analysis employing amortisation and cost effects to statically determine upper bounds on evaluation costs. While amortisation performs well with finite recursive data, we significantly improve the precision of our analysis for co-recursive programs (i.e. dealing with potentially infinite data structures) by tracking self-references. Combining these two approaches gives a fully automatic static analysis for both recursive and co-recursive definitions. The analysis is formally proven correct against an operational semantic that features an exchangeable parametric cost-model. An arbitrary measure can be assigned to all syntactic constructs, allowing to bound, for example, evaluation steps, applications, allocations, etc. Moreover, automatic inference only relies on first-order unification and standard linear programming solving. Our publicly available implementation demonstrates the practicability of our technique on editable non-trivial examples.


Automated static analysis Lazy evaluation Corecursion Amortised analysis Type systems Functional programming 

Funding information

Funder NameGrant NumberFunding Note
Seventh Framework Programme
  • 288570
Horizon 2020
  • 644235
Fundação para a Ciência e a Tecnologia
  • UID/CEC/00027/2013

Copyright information

© Springer Science+Business Media Dordrecht 2017

Authors and Affiliations

  1. 1.LMU MunichMunichGermany
  2. 2.LIACC, DCC/Faculdade de CiênciasUniversidade do PortoPortoPortugal
  3. 3.University of St AndrewsSt AndrewsUK

Personalised recommendations