Cambridge Journals Online

Cambridge Journals Online
Skip to content
Journal of Functional Programming (2002), 12: 601-607 Cambridge University Press
Copyright © 2002 Cambridge University Press
doi:10.1017/S0956796801004269
Published online by Cambridge University Press 06 Nov 2002


FUNCTIONAL PEARL

A fresh look at binary search trees


RALF HINZE a1
a1 Institute of Information and Computing Sciences, Utrecht University, P.O.Box 80.089, 3508 TB Utrecht, The Netherlands (e-mail: ralf@cs.uu.nl)

Abstract

Binary search trees are old hat, aren't they? Search trees are routinely covered in introductory computer science classes and they are widely used in functional programming courses to illustrate the benefits of algebraic data types and pattern matching. And indeed, the operation of insertion enjoys a succinct and elegant functional formulation. Figure 1 contains the six-liner given in the language Haskell 98.

Alas, both succinctness and elegance are lost when it comes to implementing the dual operation of deletion, also shown in figure 1. Two additional helper functions are required causing the code size to double in comparison with insertion.



Cambridge University Press