caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] let rec with let ref
Date: Fri, 18 Mar 2016 12:36:55 +0100	[thread overview]
Message-ID: <20160318113654.GB18511@frosties> (raw)
In-Reply-To: <CAJgjwegSKAQpG1bJEd45ksW6cr+bNopAhuRwYmUoCBmY+SrOQQ@mail.gmail.com>

On Thu, Mar 17, 2016 at 03:37:32PM +0000, vrotaru.md@gmail.com wrote:
> let rec h () = ... then h ()...
> 
> will define (and apply a function)
> 
> Iet rec value = .. value
> 
> is something totally different
> 
> În joi, 17 mar. 2016 la 17:33, Antoine Rimlet <antoine.rimlet@gmail.com> a
> scris:
> 
> > Hi,
> >
> > I'm trying to write a recursive function that would work like a for loop:
> >
> > let rec forloop g v u =
> >   let x = ref v in let rec h = begin g !x; x := !x + 1; if !x <= u then h
> > end
> >   in h;;
> >
> > I know this is horribly far from the functional spirit, but anyway ocaml
> > complains that "This kind of expression is not allowed as right-hand side
> > of `let rec'". It seems to me that this function definition has a meaning,
> > so why is it rejected? What should I do to get it accepted by ocaml?
> >
> > Many thanks in advance,
> >
> > Antoine

Also why use a ref? You need to define a function, not a value here anyway.

let rec h x = ... then h (x+1)
in h v

MfG
	Goswin

  reply	other threads:[~2016-03-18 11:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-17 15:32 Antoine Rimlet
2016-03-17 15:37 ` vrotaru.md
2016-03-18 11:36   ` Goswin von Brederlow [this message]
2016-03-18 11:55     ` Christoph Höger

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=20160318113654.GB18511@frosties \
    --to=goswin-v-b@web.de \
    --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).