From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA26366 for caml-redistribution; Sun, 10 Oct 1999 01:55:22 +0200 (MET DST) 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 AAA06745 for ; Sun, 10 Oct 1999 00:26:10 +0200 (MET DST) Received: from fiji01.liquidmarket.com (oahu02.liquidmarket.com [208.244.147.130]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id AAA07651 for ; Sun, 10 Oct 1999 00:26:07 +0200 (MET DST) Received: from maui02.liquidmarket.com (maui02.liquidmarket.com [192.168.1.65]) by fiji01.liquidmarket.com (8.8.7/8.8.7) with ESMTP id PAA02183; Sat, 9 Oct 1999 15:26:02 -0700 Message-Id: <199910092226.PAA02183@fiji01.liquidmarket.com> To: skaller Cc: caml-list@inria.fr Subject: Re: Stdlib regularity In-Reply-To: Your message of "Sat, 09 Oct 1999 00:56:26 +1000." <37FE061A.7DA264A2@maxtal.com.au> Date: Sat, 09 Oct 1999 15:26:02 -0700 From: Francois Rouaix Sender: weis writes: skaller> There are several cases where the core language prevents skaller> this, because it lacks functionality available in C++: the skaller> ability to create uninitialised values, and the ability to skaller> destroy them are two that I've become aware of trying to build skaller> a variable length array module. Uninitialized values are easily implemented with the 'a option type. Of course, the code is then ugly, because you have to match your values everywhere to None | Some x. In C/C++ terms, this forces you to check for NULL pointers systematically, which is a Really Good Thing. Adding uninitialised values is a major source of bugs, and it's kind of natural to pay the price for it in the readability of the source, if you want your code to be robust. skaller> [About a functor for an extensible array type, and the problem skaller> of a dummy value] Builtin arrays require you to provide a initialization value, even for zero-length array. Why don't you carry the same requirement to your extensible arrays, and simply use a polymorphic type: type 'a earray = { mutable current : 'a array; mutable used : int; } let create n i = { current = Array.create n i; used = n } And then, if you want to have the equivalent of NULL pointers, use None, and option types everywhere. It seems to me that you are trying to force the language to do something it has been purposely designed against. I'm not sure you can win this fight. --f