caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michel Quercia <michel.quercia@prepas.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] self and mutually recursive functions ?
Date: Thu, 10 Oct 2002 19:59:37 +0200	[thread overview]
Message-ID: <200210101959.37498.michel.quercia@prepas.org> (raw)
In-Reply-To: <20021010154738.GA12586@rhinoceros.mts>

Le Jeudi 10 Octobre 2002 17:47, Metalscan a écrit :
> Hello all of you !
>
> I'm wondering wether it is possible or not to have
> to functions defined wich are both mutually recursive
> and simply recursive.
>
> In each of them, there would be a match with one
> branch returning itself and the other one returning
> the other function.

I'm not sure to understand your problem. Do you want something like this ?

let rec f(x) = if x = 0 then f else g and g(x) = if x = 1 then g else f;;

Such a declaration will be rejected when submitted to ocaml, but can be 
accepted if you enable recursive types:

quercia@montchapet:~/lycee/02/tp-opt-info$ ocaml
        Objective Caml version 3.06

# let rec f(x) = if x = 0 then f else g and g(x) = if x = 1 then g else f;;
This expression has type int -> 'a but is here used with type 'a
# #quit;;
quercia@montchapet:~/lycee/02/tp-opt-info$ ocaml -rectypes
        Objective Caml version 3.06

# let rec f(x) = if x = 0 then f else g and g(x) = if x = 1 then g else f;;
val f : int -> 'a as 'a = <fun>
val g : int -> 'a as 'a = <fun>
# #quit;;

I doubt that the above f and g are actualy useful, but they are accepted 
anyway.

Regards,
-- 
Michel Quercia
23 rue de Montchapet, 21000 Dijon
http://michel.quercia.free.fr (maths)
http://pauillac.inria.fr/~quercia (informatique)
mailto:michel.quercia@prepas.org

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-10-10 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-10 15:47 Metalscan
2002-10-10 17:19 ` Pierre Weis
2002-10-10 17:59 ` Michel Quercia [this message]
2002-10-11 10:19 ` Pietro Abate

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=200210101959.37498.michel.quercia@prepas.org \
    --to=michel.quercia@prepas.org \
    --cc=caml-list@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).