From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr
X-Spam-Level: ***
X-Spam-Status: No, score=3.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST,
SPF_NEUTRAL autolearn=disabled version=3.1.3
X-Original-To: caml-list@yquem.inria.fr
Delivered-To: caml-list@yquem.inria.fr
Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105])
by yquem.inria.fr (Postfix) with ESMTP id 87160BB84
for ; Mon, 24 Nov 2008 23:37:23 +0100 (CET)
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: Au4AAJe7KklKfSwdkGdsb2JhbACTID4BAQEBCQkMBxEDsUWBAosFAQMBA4J5
X-IronPort-AV: E=Sophos;i="4.33,661,1220220000";
d="scan'208";a="31787220"
Received: from yx-out-2324.google.com ([74.125.44.29])
by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Nov 2008 23:37:22 +0100
Received: by yx-out-2324.google.com with SMTP id 3so948511yxj.3
for ; Mon, 24 Nov 2008 14:37:22 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:message-id:date:from:to
:subject:mime-version:content-type:content-transfer-encoding
:content-disposition;
bh=63VcqzG2QKfSPisL1Ri1UnN3wx/16CH94FOzUAv1TH4=;
b=BLj7nIcraZRM4hWOZq4u1l79oaUdVpMMwJayTl/FZoH0047K/fk0ItSR6aX4mcwbWc
CFFmzEaT2TWmWBLDELV38erm01iFaALLJMMIVnE4ObBGgy7Og/vnwU20xMc4yfbuC9Ax
kK2sRxV7bnPuxkesuCRjIanhijS+SKyEd18K8=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=message-id:date:from:to:subject:mime-version:content-type
:content-transfer-encoding:content-disposition;
b=d+BJLg4vZQ6GVCIK43djdONXJHp7mErLIQwAQa/cWprXoG9zCdJFoptTzyQCNo9Jq7
nhjTMlJtsEN/n4VjpMJHYTnLPT4ZreFQqbfwBkaPra6inh11QnTjJFpxinkoOry8PeoK
vxK+fDw1rbPmufLvWiBTYlYy7II8JSsZzdsSY=
Received: by 10.142.245.6 with SMTP id s6mr1861970wfh.213.1227566241469;
Mon, 24 Nov 2008 14:37:21 -0800 (PST)
Received: by 10.142.207.2 with HTTP; Mon, 24 Nov 2008 14:37:21 -0800 (PST)
Message-ID: <4b5157c30811241437y64d1087au9c50c40f303b2c70@mail.gmail.com>
Date: Mon, 24 Nov 2008 23:37:21 +0100
From: "Paolo Donadeo"
To: "OCaml mailing list"
Subject: A function returning itself
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Spam: no; 0.00; ocamlc:01 -rectypes:01 ocamlc:01 -rectypes:01 val:01 rec:01 compile:01 computation:01 computation:01 int:01 int:01 expression:02 inferred:02 archives:02 seems:03
Hi everybody, I need your help again.
In a particular application I need (or at least I think so...) to
create a function that, besides it's own computation, returns itself.
Something like:
$ cat test.ml
let rec f a b =
let computation = a + b in
(computation, f)
;;
This file doesn't compile; the error is:
$ ocamlc -c test.ml
File "test.ml", line 3, characters 4-20:
This expression has type int * (int -> int -> int * 'a)
but is here used with type int * 'a
If I use the -rectypes option, it seems to work, even though the
inferred type is quite cryptic (to me):
$ ocamlc -c -rectypes -i test.ml
val f : int -> int -> int * 'a as 'a
Since I don't completely understand the inner implications of
-rectypes and a quick check in the mailing list archives revealed that
"rectypes is evil", the question I pose is whether is it possible to
avoid the -rectypes option in this particular case, possibly with the
definition of an auxiliary type.
My idea is that the function makes a computation and then decides if
the next computation of the same type will be carried out by "f"
itself, or by another function with identical signature.
--
Paolo
~
~
:wq