From: "Krishnaswami, Neel" <neelk@cswcasa.com>
To: "'Franck'" <franck.collineau@francetelecom.com>, caml-list@inria.fr
Subject: RE: [Caml-list] Great Beginner
Date: Fri, 9 Nov 2001 09:10:00 -0500 [thread overview]
Message-ID: <B1E4D3274D57D411BE8400D0B783FF32A8D59A@exchange1.cswv.com> (raw)
Franck [mailto:franck.collineau@francetelecom.com] wrote:
> Hello!
> I have written the following code:
> let somme(x,n)=
> for i=1 to i=n
> do
> x<-x+1
> done;;
>
> caml tel me that i is not define. What is the problem ?
You have a couple of syntax errors. First, the syntax of a
for-loop is
"for i = 1 to n do <foo> done"
Second, your assignment statement x <- x + 1 has the wrong syntax,
and the wrong type. If you want to do an assignment, you need to
use the (:=) operator, like this:
x := 5
(:=) has the type 'a ref -> 'a -> unit, which means that the left
hand side should be a reference, and the right hand side should be
the value you want the reference to point to. However, when you
write:
x := x + 1
you will get a type error, because x has type int ref, and (+) has
type int -> int -> int. So to do the addition you need to dereference
the reference:
let somme(x, n) =
for i = 1 to n do
x := !x + 1
done
which has type int ref -> int -> unit. This doesn't look like a
function I would want to write, but maybe you do. :)
--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next reply other threads:[~2001-11-09 14:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-09 14:10 Krishnaswami, Neel [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-11-09 13:44 Franck
2001-11-11 11:34 ` Remi VANICAT
2001-11-10 15:29 ` Diego Olivier Fernandez Pons
2001-11-12 6:39 ` Remi VANICAT
2001-11-12 8:13 ` Diego Olivier Fernandez Pons
2001-11-09 11:08 Franck
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=B1E4D3274D57D411BE8400D0B783FF32A8D59A@exchange1.cswv.com \
--to=neelk@cswcasa.com \
--cc=caml-list@inria.fr \
--cc=franck.collineau@francetelecom.com \
/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