Re: boolean in OCaml

"Philippe Veber [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAOOOohQ2v_vfkNE2o09Jceo83HEi36ujqMSf__M20_mzW1Ppcw@mail.gmail.com>
Hi,

variables in OCaml are immutable by default, the preferred style being
functional. If you really need to use an imperative style and modify
variables, you shoud use references:

let whilecmd = ref false
...
whilecmd := true

To get a better idea of this, you could read the first chapter of RWO [1],
which briefly illustrates the two styles.

Cheers,
  Philippe.

[1] https://realworldocaml.org/v1/en/html/a-guided-tour.html



2014-08-08 6:57 GMT+02:00 [email protected] [ocaml_beginners] <
[email protected]>:

>
>
> Hi,
>
> I defined a boolean variable in a .ml file using OCaml like that:
>
> let whilecmd = false
>
> and somewhere I assign true to this boolean variable :
>
> whilecmd=true;  (It gives a warning : this expression should have type
> unit)
>
> and it doesn't work. The boolean whilecmd is still false.
>
> Can anyone help me?
>
>
> Thanks
>
>
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.