caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* polymorphic recursion
@ 2008-05-12 21:55 Jacques Le Normand
  2008-05-12 22:16 ` [Caml-list] " Christophe TROESTLER
  0 siblings, 1 reply; 18+ messages in thread
From: Jacques Le Normand @ 2008-05-12 21:55 UTC (permalink / raw)
  To: caml-list caml-list

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

Hello list,
I'm having trouble finding information on this; does ocaml support
polymorphic recursion and, if so, what's the syntax?
--Jacques

[-- Attachment #2: Type: text/html, Size: 160 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Polymorphic recursion
@ 2007-04-03 16:59 Loup Vaillant
  2007-04-04 13:49 ` [Caml-list] " Roland Zumkeller
  0 siblings, 1 reply; 18+ messages in thread
From: Loup Vaillant @ 2007-04-03 16:59 UTC (permalink / raw)
  To: caml-list

I was reading Okasaki's book, "Purely functionnal data structures",
and discovered that ML (and Ocaml) doesn't support non uniforms
function definitions.

So, even if:

(**)
type 'a seq = Unit | Seq of ('a * ('a * 'a)seq);;
(**)

is correct,

(**)
let rec size = fun
   | Unit -> 0
   | Seq(_, b) -> 1 + 2 * size b;;
(**)

is not. Here is the error:
#
| Seq(_, b) -> 1 + 2 * size b;;
This expression (the last 'b') has type seq ('a * 'a) but is here used
with type seq 'a
#

Why?
Can't we design a type system which allow this "size" function?
Can't we implement non uniform recursive function (efficiently, or at all)?.

I suppose the problem is somewhat difficult, but I can't see where.

Regards,
Loup Vaillant


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Polymorphic recursion
@ 1999-08-22 20:35 Hongwei Xi
  1999-08-23 12:19 ` Pierre Weis
  0 siblings, 1 reply; 18+ messages in thread
From: Hongwei Xi @ 1999-08-22 20:35 UTC (permalink / raw)
  To: caml-list

Hi,

Could anyone tell me whether the feature of polymorphic
recursion is available in Caml-light or OCaml? If so,
how to use it (a simply example would suffice)?

Thanks,

--Hongwei

\~~~~/ \\   //  \\    //    @       Mail: hongwei@cse.ogi.edu
C-o^o,  ))__||   \\__//_  // \\     Url: http://www.cse.ogi.edu/~hongwei
(  ^ )  ))__||    \--/-\\     \\    Tel: +1 503 748 1584 (office)
/ \V\   ))  ||     //   \\     \\   Fax: +1 503 748 1553 (department)
------ //   || o  //     \\     \\// 
Department of Computer Science and Engineering
Oregon Graduate Institute of Science and Technology
P. O. Box 91000, Portland, OR 97291-1000, USA




^ permalink raw reply	[flat|nested] 18+ messages in thread
* polymorphic recursion
@ 1998-09-21 16:30 Peter J Thiemann
  1998-09-22  2:33 ` Jacques GARRIGUE
  0 siblings, 1 reply; 18+ messages in thread
From: Peter J Thiemann @ 1998-09-21 16:30 UTC (permalink / raw)
  To: caml-list; +Cc: pjt

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





^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2008-05-12 22:16 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-12 21:55 polymorphic recursion Jacques Le Normand
2008-05-12 22:16 ` [Caml-list] " Christophe TROESTLER
  -- strict thread matches above, loose matches on Subject: below --
2007-04-03 16:59 Polymorphic recursion Loup Vaillant
2007-04-04 13:49 ` [Caml-list] " Roland Zumkeller
2007-04-04 15:13   ` Alain Frisch
2007-04-04 15:50     ` Stefan Monnier
1999-08-22 20:35 Hongwei Xi
1999-08-23 12:19 ` Pierre Weis
1998-09-21 16:30 polymorphic recursion Peter J Thiemann
1998-09-22  2:33 ` Jacques GARRIGUE
1998-09-22  9:22   ` Pierre Weis
1998-09-22 10:00     ` Simon Helsen
1998-09-22 15:06       ` Pierre Weis
1998-09-22 15:28         ` Simon Helsen
1998-09-22 16:33           ` Pierre Weis
1998-09-22 15:50         ` Pierre CREGUT - FT.BD/CNET/DTL/MSV
1998-09-22 17:14           ` Xavier Leroy
1998-09-28  9:51             ` Pierre Weis
1998-09-28 11:45               ` Peter Thiemann
1998-09-28 13:00                 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).