A type system for bounded space and functional in-place update

  • Authors:
  • Martin Hofmann

  • Affiliations:
  • Division of Informatics University of Edinburgh Mayfield Rd Edinburgh EH9 3JZ, UK

  • Venue:
  • Nordic Journal of Computing
  • Year:
  • 2000

Quantified Score

Hi-index 0.00

Visualization

Abstract

We show how linear typing can be used to obtain functional programs which modify heap-allocated data structures in place.We present this both as a "design pattern" for writing C-code in a functional style and as a compilation process from linearly typed first-order functional programs into malloc ()-free C code.The main technical result is the correctness of this compilation.The crucial innovation over previous linear typing schemes consists of the introduction of a resource type ♦ which controls the number of constructor symbols such as cons in recursive definitions and ensures linear space while restricting expressive power surprisingly little.While the space efficiency brought about by the new typing scheme and the compilation into C can also be realised by with state-of-the-art optimising compilers for functional languages such as OCAML [16], the present method provides guaranteed bounds on heap space which will be of use for applications such as languages for embedded systems or automatic certification of resource bounds.We show that the functions expressible in the system are precisely those computable on a linearly space-bounded Turing machine with an unbounded stack. By a result of Cook this equals the complexity class 'exponential time'. A tail recursive fragment of the language captures the complexity class 'linear space'.We discuss various extensions, in particular an extension with FIFO queues admitting constant time catenation and enqueuing, and an extension of the type system to fully-fledged intuitionistic linear logic.