[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Peter J Thiemann <pjt@c...> |
| 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
x;;
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
x
Question:
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.
-Peter