caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Mutual recursion propagates individual recursion. Why?
@ 2015-03-02  6:25 Jordan W
  2015-03-02  7:25 ` Gabriel Scherer
  0 siblings, 1 reply; 5+ messages in thread
From: Jordan W @ 2015-03-02  6:25 UTC (permalink / raw)
  To: caml-list

(Note: When trying any of these examples, make sure to kill/restart
your top level between each examples - non-recursive bindings that
should fail will appear to work because they use existing bindings in
the environment).

My understanding is that self-recursion in OCaml is introduced via the
`let rec` binding keyword pair.

    let rec x a = x a


A sequence of let bindings are made *both* mutually recursive, *and*
individually self-recursive via a combination of `let rec` and the
`and` keyword.

   (* Notice how y is made self recursive as well *)
   let rec x a = (x a + y a) and y a = (x a + y a);;

The `and` keyword by itself is not sufficient to introduce mutual
recursion, and not sufficient to introduce self-recursion for any of
the bindings joined by the `and`.

    (* Does not work *)
    let x a = x a and y a = (x a + y a)
    (* Does not work *)
    let x a = y a and y a = x a


My questions are:
1. Is there any effect to having the `and` keyword, without a `let
rec` that initiates the let binding sequence?
2. Is there any way to introduce mutual recursion without also
introducing self-recursion on *all* of the bindings?

I would like self-recursion to be independent from mutual recursion.
It would be nice to be able to create several mutually recursive
bindings that are not individually self-recursive. I imagine the
syntax to accomplish this would require each binding to be opened with
"let" or "let rec" which would be totally reasonable.

    (* Three mutually recursive functions that are not self-recursive *)
    let rec thisOneIsSelfRecursive x = ... and
    let thisOneIsNotSelfRecursive y = ... and
    let rec thisOneIsAlsoSelfRecursive z = ...;

This becomes more desirable when one of the mutually recursive
bindings is a non-function value that you did not want to make
self-recursive by accident (which causes cycles).

Jordan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-02  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-02  6:25 [Caml-list] Mutual recursion propagates individual recursion. Why? Jordan W
2015-03-02  7:25 ` Gabriel Scherer
2015-03-02  9:14   ` Ben Millwood
2015-03-02  9:18   ` Jordan W
2015-03-02  9:49     ` Ben Millwood

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).