English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2001-09-12 (07:22)
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:


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


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