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 KAA13018; Thu, 14 Jun 2001 10:53:35 +0200 (MET DST) 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 KAA12965 for ; Thu, 14 Jun 2001 10:53:34 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f5E8rWj01920 for ; Thu, 14 Jun 2001 10:53:32 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id RAA15792; Thu, 14 Jun 2001 17:53:27 +0900 (JST) To: leary@nwlink.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] enums in OCaml? In-Reply-To: <20010614011550.A28578@jean> References: <20010612192126.B24440@jean> <20010614011550.A28578@jean> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010614175327U.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 14 Jun 2001 17:53:27 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > So, what's so wrong with just using variables? > > let Accel = 1;; > let Stop = 0;; > > seems pretty short to write and shortest to use... Am I missing something > ( elegant | obvious )? Is that just ugly? If you use sum types, the compiler will * check that in any pattern matching, or collection of objects (e.g. list), you only use constructors of the same sum type * check whether your pattern matches are exhaustive or not, and avoid adding a default "_ -> .." clause at the end These two checks take something like half of the bugs in any program. So yes, this is paramount to use sum types rather than named constants. The only case you want to use named constants is when you do not have an exhaustive list of cases available, and want to be able to add cases afterwards, making the above checks impossible. Even in this case you may want to go for hybrid solutions, including a sum type for the cases you know, but this is a bit more high-level. Jacques Garrigue ------------------- 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