Catch Me If You Can

Looking for Type-Safe, Hierarchical, Lightweight, Polymorphic and Efficient Error Management in OCaml
  • David Teller
  • Arnaud Spiwack
  • Till Varoquaux
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5836)


This is the year 2008 and ML-style exceptions are everywhere. Most modern languages, whether academic or industrial, feature some variant of this mechanism. Languages such as Java even feature static coverage-checking for such exceptions, something not available for ML languages, at least not without resorting to external tools.

In this document, we demonstrate a design principle and a tiny library for managing errors in a functional manner, with static coverage-checking, automatically-inferred, structurally typed and hierarchical exceptional cases, with a reasonable run-time penalty. Our work is based on OCaml and features monads, polymorphic variants, compile-time code rewriting and trace elements of black magic.


Error Case Polymorphic Variant Error Management Short Execution Time Syntactic Sugar 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Blume, M., Acar, U.A., Chae, W.: Exception handlers as extensible cases. In: Ramalingam, G. (ed.) APLAS 2008. LNCS, vol. 5356, pp. 273–289. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  2. 2.
    Warren Burton, F.: Type extension through polymorphism. ACM Trans. Program. Lang. Syst. 12(1), 135–138 (1990)CrossRefGoogle Scholar
  3. 3.
    Carette, J., Kiselyov, O.: Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code. In: Glück, R., Lowry, M. (eds.) GPCE 2005. LNCS, vol. 3676, pp. 256–274. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  4. 4.
    Carette, J., van Dijk, L.E., Kiselyov, O.: Syntax extension for monads in ocaml,
  5. 5.
    Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W.: Dsl implementation in metaocaml, template haskell, and c++. In: Domain-Specific Program Generation, pp. 51–72 (2003)Google Scholar
  6. 6.
    Fluet, M., Pucella, R.: Phantom types and subtyping. In: TCS 2002: Proceedings of the IFIP 17th World Computer Congress - TC1 Stream / 2nd IFIP International Conference on Theoretical Computer Science, Deventer, The Netherlands, pp. 448–460. Kluwer, B.V., Dordrecht (2002)Google Scholar
  7. 7.
    Garrigue, J.: Programming with polymorphic variants. In: ML Workshop (1998)Google Scholar
  8. 8.
    Garrigue, J.: Relaxing the value restriction. In: Kameyama, Y., Stuckey, P.J. (eds.) FLOPS 2004. LNCS, vol. 2998, pp. 196–213. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  9. 9.
    Guyer, S.Z., Lin, C.: An annotation language for optimizing software libraries. In: DSL, pp. 39–52 (1999)Google Scholar
  10. 10.
    Holt, R.C., Wortman, D.B.: A sequence of structured subsets of pl/i. SIGCSE Bull. 6(1), 129–132 (1974)CrossRefGoogle Scholar
  11. 11.
    Marlow, S.: An extensible dynamically-typed hierarchy of exceptions. In: Haskell 2006: ACM SIGPLAN Workshop on Haskell, Portland, Oregon, ACM Press, New York (2006)Google Scholar
  12. 12.
    Milner, R., Tofte, M., Macqueen, D.: The Definition of Standard ML. MIT Press, Cambridge (1990)Google Scholar
  13. 13.
    Mitchell, N., Runciman, C.: A static checker for safe pattern matching in Haskell. In: Trends in Functional Programming, vol. 6. Intellect (February 2007)Google Scholar
  14. 14.
    Pessaux, F.: Détection statique d’exceptions non rattrapées en Objective Caml. PhD thesis, Université Pierre & Marie Curie - Paris 6 (2000)Google Scholar
  15. 15.
    Ramsey, N.: Eliminating spurious error messages using exceptions, polymorphism, and higher-order functions. The Computer Journal 42(5), 360–372 (1999)CrossRefzbMATHGoogle Scholar
  16. 16.
    Rossberg, A., Le Botlan, D., Tack, G., Brunklaus, T., Smolka, G.: Alice through the looking glass. In: Trends in Functional Programming, vol. 5, pp. 77–96 (2006)Google Scholar
  17. 17.
    Talpin, J.-P., Jouvelot, P.: The type and effect discipline. Inf. Comput. 111(2), 245–296 (1994)MathSciNetCrossRefzbMATHGoogle Scholar
  18. 18.
    Teller, D., Spiwack, A., Varoquaux, T.: Catch me if you can, Software package available at
  19. 19.
    Wadler, P.: The essence of functional programming. In: POPL 1992: Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 1–14. ACM, New York (1992)Google Scholar
  20. 20.
    Yi, K., Ryu, S.: A cost-effective estimation of uncaught exceptions in standard ml programs. Theor. Comput. Sci. 277(1-2), 185–217 (2002)MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • David Teller
    • 1
  • Arnaud Spiwack
    • 2
  • Till Varoquaux
    • 2
  1. 1.LIFOUniversité d’OrléansFrance
  2. 2.LIX, École PolytechniqueFrance

Personalised recommendations