caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Paolo Donadeo" <p.donadeo@gmail.com>
To: "OCaml mailing list" <caml-list@yquem.inria.fr>
Subject: A function returning itself
Date: Mon, 24 Nov 2008 23:37:21 +0100	[thread overview]
Message-ID: <4b5157c30811241437y64d1087au9c50c40f303b2c70@mail.gmail.com> (raw)

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


             reply	other threads:[~2008-11-24 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-24 22:37 Paolo Donadeo [this message]
2008-11-24 22:43 ` [Caml-list] " Mathias Kende
2008-11-24 22:49   ` Paolo Donadeo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b5157c30811241437y64d1087au9c50c40f303b2c70@mail.gmail.com \
    --to=p.donadeo@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).