* [Caml-list] Why warning?
@ 2001-09-12 6:22 SooHyoung Oh
2001-09-12 7:00 ` Christian RINDERKNECHT
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: SooHyoung Oh @ 2001-09-12 6:22 UTC (permalink / raw)
To: caml-list
Why is this warning occurred?
Where can I get infomation about this? (ex: 'nnn' page on manual, articles
or books)
# 1; 2;;
Warning: this expression should have type unit.
- : int = 2
--- SooHyoung Oh
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Why warning?
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
@ 2001-09-12 7:00 ` Christian RINDERKNECHT
2001-09-12 7:18 ` Sven
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christian RINDERKNECHT @ 2001-09-12 7:00 UTC (permalink / raw)
To: SooHyoung Oh; +Cc: caml-list
Hi Soo-Hyoung,
On Wed, Sep 12, 2001 at 03:22:32PM +0900, SooHyoung Oh wrote:
>
> Why is this warning occurred?
> Where can I get infomation about this? (ex: 'nnn' page on manual, articles
> or books)
>
> # 1; 2;;
> Warning: this expression should have type unit.
> - : int = 2
The sequence operator ; (semi-colon) is used for composing expressions
that may perform some side-effects. This is the typical construct of
imperative languages like Pascal. In Caml, such expressions are given
the type unit, and the only value of type unit is noted (). It
is generally considered as good practice to:
(1) make sure that the expressions are of type unit, except maybe
the last one, ie. given <e1>; <e2>; .... ; <en>; <e'>, then
<e1>, <e2>, ..., <en> should have type unit;
(2) use keywords "begin" and "end" to enclose your sequence:
begin
<e1>;
<e2>;
...
<en>;
<e'>
end
So, in your example, 1 is of type int, not unit (hence the warning).
For historical reason, this behaviour is not mandatory, and you can
turn off this warning in batch mode usign the -W s command-line
option. Please refer to
http://caml.inria.fr/ocaml/htmlman/manual021.html for other warnings.
As far as I am concerned, all warnings are turned into errors:)
Hope this helps,
--
Christian
-----------------------------------------------------------------------
Christian Rinderknecht Phone +82 42 866 6147
Network Architecture Laboratory Fax +82 42 866 6154
Information and Communications University WWW http://nalab.icu.ac.kr
58-4 Hwaam-dong, Yuseong-gu, Daejeon,
305-752, Korea
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Why warning?
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
2001-09-12 7:00 ` Christian RINDERKNECHT
@ 2001-09-12 7:18 ` Sven
2001-09-12 7:22 ` Jean-Christophe Filliatre
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sven @ 2001-09-12 7:18 UTC (permalink / raw)
To: SooHyoung Oh; +Cc: caml-list
On Wed, Sep 12, 2001 at 03:22:32PM +0900, SooHyoung Oh wrote:
>
> Why is this warning occurred?
> Where can I get infomation about this? (ex: 'nnn' page on manual, articles
> or books)
>
> # 1; 2;;
> Warning: this expression should have type unit.
> - : int = 2
Because you are throwing away the 1 value, and mostly you don't want to do
this, and it is a symptom of a typo or other kind of bug in your program.
There trully is no real difference bewteen 1; 2 and simply 2, they are
the exact same values. The only reason you would want to do something like
that is if you use functions with side effect, in this case, you can either
switch off this warning (not recomended) or use the ignore : 'a -> unit
function :
# ignore (1); 2;;
- : int = 2
Which does exactly what you want, without the warning.
Friendly,
Sven Luther
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Why warning?
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
2001-09-12 7:00 ` Christian RINDERKNECHT
2001-09-12 7:18 ` Sven
@ 2001-09-12 7:22 ` Jean-Christophe Filliatre
2001-09-12 8:47 ` David Mentre
2001-09-13 16:39 ` Pierre Weis
4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe Filliatre @ 2001-09-12 7:22 UTC (permalink / raw)
To: SooHyoung Oh; +Cc: caml-list
SooHyoung Oh writes:
>
> Why is this warning occurred?
> Where can I get infomation about this? (ex: 'nnn' page on manual, articles
> or books)
>
> # 1; 2;;
> Warning: this expression should have type unit.
> - : int = 2
In the sequence "expr1; expr2", the result of expr1 is discarded.
Thus, whenever the result of expr1 is not "()" (i.e. expr1 is not of
type "unit") the Caml compiler gives you a warning (you may have typed
";" instead of "," for instance, or any similar typo)
This warning may be disabled, as explained in the manual:
http://caml.inria.fr/ocaml/htmlman/manual021.html
But you should rather write your code in a different way, having expr1
of type unit, or explicitly ignoring its result. There are (at least)
two possibilities:
let _ = expr1 in expr2
or better
ignore (expr1); expr2
"ignore" is part of the Caml code library; see
http://caml.inria.fr/ocaml/htmlman/manual031.html#@manual94
Best regards,
--
Jean-Christophe Filliatre (http://www.lri.fr/~filliatr)
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Why warning?
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
` (2 preceding siblings ...)
2001-09-12 7:22 ` Jean-Christophe Filliatre
@ 2001-09-12 8:47 ` David Mentre
2001-09-13 16:39 ` Pierre Weis
4 siblings, 0 replies; 6+ messages in thread
From: David Mentre @ 2001-09-12 8:47 UTC (permalink / raw)
To: SooHyoung Oh; +Cc: caml-list
"SooHyoung Oh" <shoh@duonix.com> writes:
> Where can I get infomation about this? (ex: 'nnn' page on manual, articles
> or books)
I've not found any pointer that explains this specific point.
> # 1; 2;;
> Warning: this expression should have type unit.
> - : int = 2
If you decompose this expression, you have:
# 1;;
- : int = 1 <-- notice the type of '1' is 'int'
# 2;;
- : int = 2
In an expression 'expr1 ; expr2', expr1 should have type unit as its
result is not accessible to expr2.
Hope it helps,
d.
--
David.Mentre@inria.fr
Opinions expressed here are only mine.
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Why warning?
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
` (3 preceding siblings ...)
2001-09-12 8:47 ` David Mentre
@ 2001-09-13 16:39 ` Pierre Weis
4 siblings, 0 replies; 6+ messages in thread
From: Pierre Weis @ 2001-09-13 16:39 UTC (permalink / raw)
To: SooHyoung Oh; +Cc: caml-list
> Why is this warning occurred?
> Where can I get infomation about this? (ex: 'nnn' page on manual, articles
> or books)
>
> # 1; 2;;
> Warning: this expression should have type unit.
> - : int = 2
>
> --- SooHyoung Oh
Have a look to the FAQ:
http://pauillac.inria.fr/caml/FAQ/pgl-eng.html#avertissements
paragraph entitled ``Sequence warnings''.
Different ways of getting rid of the warning are discussed, including
the most demanding one (and, to my knowledge, the best one): ``understand why
(the warning) is emitted by the compiler''.
Best regards,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
-------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-09-13 16:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-12 6:22 [Caml-list] Why warning? SooHyoung Oh
2001-09-12 7:00 ` Christian RINDERKNECHT
2001-09-12 7:18 ` Sven
2001-09-12 7:22 ` Jean-Christophe Filliatre
2001-09-12 8:47 ` David Mentre
2001-09-13 16:39 ` Pierre Weis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox