Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] self and mutually recursive functions ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michel Quercia <michel.quercia@p...>
Subject: Re: [Caml-list] self and mutually recursive functions ?
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