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 PAA31019; Wed, 8 May 2002 15:32:52 +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 PAA31004 for ; Wed, 8 May 2002 15:32:51 +0200 (MET DST) Received: from smtp2.cswv.com (smtp2.cswv.com [4.17.129.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g48DWo906663 for ; Wed, 8 May 2002 15:32:50 +0200 (MET DST) Received: from smtp2.cswv.com ([10.2.3.6]) by smtp2.cswv.com with Microsoft SMTPSVC(5.5.1877.197.19); Wed, 8 May 2002 09:32:43 -0400 Received: FROM exchange1.cswv.com BY smtp2.cswv.com ; Wed May 08 09:32:43 2002 -0400 Received: by exchange1.cswv.com with Internet Mail Service (5.5.2653.19) id ; Wed, 8 May 2002 09:33:04 -0400 Message-ID: From: "Krishnaswami, Neel" To: "Caml Mailing List (E-mail)" Subject: Re: [Caml-list] Naming conventions Date: Wed, 8 May 2002 09:33:03 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="koi8-r" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Paul Stodghill [mailto:stodghil@CS.Cornell.EDU] wrote: > > In Scheme, there is a conventtion that the names of > destructive functions end with "!" and predicates end with > "?". E.g., "append!" vs. "append", and "null?", "pair?", etc. > > Are there any similar conventions that people use in O'Caml? Yes. The usual convention is that mutating functions return the unit value. Eg: Hashtbl.add : 'a t -> key -> data:'a -> unit (* Mutable collection *) Map.add : key -> 'a -> 'a t -> 'a t (* Immutable collection *) Each type usually has two iterators, as well -- one named "fold" for the usual applicative folds, and another named "iter" for folding a destructive procedure over a datastructure. Eg: fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b iter : (key -> 'a -> unit) -> 'a t -> unit Since the imperative and applicative versions have different type, I suppose this convention might cause problems if you want to be able to transparently replace the pure versions with the destructive versions. In that case, I'd suggest inventing your own convention; perhaps you could use unprimed and primed names with the same types, to denote pure and destructive operations. Eg; Mytype.add : key -> 'a -> 'a t -> 'a t (* Pure *) Mytype.add' : key -> 'a -> 'a t -> 'a t (* Imperative *) -- Neel Krishnaswami neelk@cswcasa.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners