polymorphic recursion

From: Peter J Thiemann (pjt@cs.nott.ac.uk)
Date: Mon Sep 21 1998 - 18:30:34 MET DST

Date: Mon, 21 Sep 1998 17:30:34 +0100
From: Peter J Thiemann <pjt@cs.nott.ac.uk>
To: caml-list@inria.fr
Subject: polymorphic recursion

In some languages (most notably Haskell and Miranda) it is possible
to define a function that enjoys polymorphic recursion, i.e., the
types of its recursive calls may be instances of the type scheme at
which the function is defined.

For example:

let rec f x =
  let q = f true in
  let r = f 0 in

is rejected by OCaml, but it is accepted by Haskell by saying

f :: a -> a
f x = let q = f True in
      let r = f 0 in


Can you do the same in OCaml? I am aware of the tricks mentioned in
the FAQ, but I would like to know if there is a cleaner way to do it,
for example by providing a type signature.


This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:16 MET