From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 51B3BBBAF for ; Fri, 23 Oct 2009 00:22:40 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskBAKt34ErV+4o8kWdsb2JhbACbKgEBAQEJCwoHE8ByhD8E X-IronPort-AV: E=Sophos;i="4.44,608,1249250400"; d="scan'208";a="36843428" Received: from 39.mail-out.ovh.net ([213.251.138.60]) by mail3-smtp-sop.national.inria.fr with SMTP; 23 Oct 2009 00:22:39 +0200 Received: (qmail 4868 invoked by uid 503); 22 Oct 2009 22:23:01 -0000 Received: from b6.ovh.net (HELO mail642.ha.ovh.net) (213.186.33.56) by 39.mail-out.ovh.net with SMTP; 22 Oct 2009 22:23:01 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 22 Oct 2009 22:23:08 -0000 Received: from rezo-159-5.ens.fr (HELO ?129.199.159.5?) (mathias@kende.eu@129.199.159.5) by ns0.ovh.net with SMTP; 22 Oct 2009 22:23:06 -0000 Subject: forbidden construct as right hand side of "let rec" From: Mathias Kende Reply-To: mathias@kende.fr To: caml-list@yquem.inria.fr Content-Type: text/plain Date: Fri, 23 Oct 2009 00:22:01 +0200 Message-Id: <1256250121.4178.37.camel@MATHIAS-ENS> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 15801442244630353119 X-Ovh-Remote: 129.199.159.5 (rezo-159-5.ens.fr) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.90895/N X-Spam: no; 0.00; compiler:01 ocaml:01 rec':01 recursive:01 ocaml:01 mathias:98 mathias:98 rec:01 rec:01 right-hand:01 define:02 expression:02 parameter:02 construct:02 let:03 Hello list, I need to write something like this : let f f i = if i = 0 then 1 else i * f (i - 1) let rec g = f g Of course the compiler won't let me write it (even if the OCaml type system is happy): "This kind of expression is not allowed as right-hand side of `let rec'" But as the function parameter of function f is used only for a recursive call I believe that the function I try the define is at least "morally" correct. Is there a way to express this sort of construction in OCaml ? My aim is to be able to have some things equivalent to: let rec g = f g and let rec h = t (f h) where t is some transformation over the function (conserving its type), and still writing the code for f only once. Regards, Mathias