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:17)
From: Sven <luther@d...>
Subject: Re: [Caml-list] Why warning?
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.


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