Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Naming conventions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Krishnaswami, Neel <neelk@c...>
Subject: Re: [Caml-list] Naming conventions
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
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: