* [Caml-list] self and mutually recursive functions ?
@ 2002-10-10 15:47 Metalscan
2002-10-10 17:19 ` Pierre Weis
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Metalscan @ 2002-10-10 15:47 UTC (permalink / raw)
To: caml-list
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.
Thanks for your help.
Matthieu Dubuget
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] self and mutually recursive functions ?
2002-10-10 15:47 [Caml-list] self and mutually recursive functions ? Metalscan
@ 2002-10-10 17:19 ` Pierre Weis
2002-10-10 17:59 ` Michel Quercia
2002-10-11 10:19 ` Pietro Abate
2 siblings, 0 replies; 4+ messages in thread
From: Pierre Weis @ 2002-10-10 17:19 UTC (permalink / raw)
To: Metalscan; +Cc: caml-list
> 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.
>
> Thanks for your help.
>
> Matthieu Dubuget
Typically a FAQ question. Look at
FAQ: http://caml.inria.fr/FAQ/
If this is not enough, post to the beginners group at
http://groups.yahoo.com/group/ocaml_beginners
All the best for learning Caml.
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] self and mutually recursive functions ?
2002-10-10 15:47 [Caml-list] self and mutually recursive functions ? Metalscan
2002-10-10 17:19 ` Pierre Weis
@ 2002-10-10 17:59 ` Michel Quercia
2002-10-11 10:19 ` Pietro Abate
2 siblings, 0 replies; 4+ messages in thread
From: Michel Quercia @ 2002-10-10 17:59 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] self and mutually recursive functions ?
2002-10-10 15:47 [Caml-list] self and mutually recursive functions ? Metalscan
2002-10-10 17:19 ` Pierre Weis
2002-10-10 17:59 ` Michel Quercia
@ 2002-10-11 10:19 ` Pietro Abate
2 siblings, 0 replies; 4+ messages in thread
From: Pietro Abate @ 2002-10-11 10:19 UTC (permalink / raw)
To: caml-list
On Thu, Oct 10, 2002 at 05:47:38PM +0200, Metalscan wrote:
> In each of them, there would be a match with one
> branch returning itself and the other one returning
> the other function.
do you want something like that ?
let rec f1 i =
match i with
| 1 -> f1 (i-1)
| 2 -> f2 (i-1)
| a -> let _ = Printf.printf "f1 = %d\n" a in a
and f2 j =
match j with
| 1 -> f2 (j-1)
| 2 -> f1 (j-1)
| a -> let _ = Printf.printf "f2 = %d\n" a in a
;;
# f1 1;;
f1 = 0
- : int = 0
# f1 2;;
f2 = 0
- : int = 0
regards,
p
--
pgp key: 1024D/8A091922 2000-10-18 Pietro Abate <abate@arp.anu.edu.au>
Key fingerprint = 5111 D91B 5E0C 5CE6 FDA3 5EF4 6120 E18E 8A09 1922
public key avalaible via public key server at wwwkeys.eu.pgp.net
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-10-11 10:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-10 15:47 [Caml-list] self and mutually recursive functions ? Metalscan
2002-10-10 17:19 ` Pierre Weis
2002-10-10 17:59 ` Michel Quercia
2002-10-11 10:19 ` Pietro Abate
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox