how to coerce expression type?

From: Dwight VandenBerghe (dwight@pentasoft.com)
Date: Mon Dec 21 1998 - 18:17:06 MET


Message-Id: <3.0.32.19981221091704.00bcd310@seanet.com>
Date: Mon, 21 Dec 1998 09:17:06 -0800
To: caml-list@inria.fr
From: Dwight VandenBerghe <dwight@pentasoft.com>
Subject: how to coerce expression type?

I am converting older ocaml code to version 2.01, and
find that many expressions that passed through the previous
compilers fine now exhibit warning errors due to not being
of unit type. This happens when I evaluate an expression
for its side effects (the horror, the horror). Here's an
example:

  let is_in_table table key =
     try
         Hashtbl.find table key;
         true
     with Not_found -> false;;

I don't want the result back from the lookup, I just want
to know if the key was present. So how do I "cast" the
find operation to unit, to quiet the warnings? I've tried
everything I can think of, things like

         (Hashtbl.find table key) : ()

but have not yet hit upon the magic incantation.

Thank you.

Dwight



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:17 MET