From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA05683; Sun, 17 Feb 2002 14:50:13 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA05283 for ; Sun, 17 Feb 2002 14:48:52 +0100 (MET) Received: from beaune.inria.fr (beaune.inria.fr [128.93.8.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g1HDmpv04977 for ; Sun, 17 Feb 2002 14:48:51 +0100 (MET) Received: by beaune.inria.fr (8.8.8/1.1.22.3/14Sep99-0328PM) id OAA0000013262; Sun, 17 Feb 2002 14:47:30 +0100 (MET) Date: Sun, 17 Feb 2002 14:47:30 +0100 (MET) From: Damien Doligez Message-Id: <200202171347.OAA0000013262@beaune.inria.fr> To: caml-list@inria.fr, jhw@wetware.com Subject: Re: [Caml-list] assertions and branch prediction Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >From: james woodyatt > match p with > | A -> ...; () > | B -> ...; () > | _ -> assert false > >Then I hit upon the idea of rewriting it this way: > > assert (p = A || p = B); > match p with > | A -> ...; () > | B -> ...; () > | C -> () > >My thinking was that I would rather pay up front with a more expensive >assertion, one that can be stripped out later with the -noassert option, >rather than pay at deployment with code (for raising the Assert_failure >exception) that I've eventually proven will not be executed. You can have the best of both worlds by writing it like this: match p with | A -> ...; () | B -> ...; () | _ -> assert (not true); () As for "assert false" with -noassert, you're not really supposed to catch the Assert_failure exception (unless you really know what you're doing), so it should result in the immediate termination of your program anyway. -- Damien ------------------- 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