Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why warning?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Why warning?

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