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: 2002-05-08 (13:31)
From: Gregory Morrisett <jgm@C...>
Subject: RE: [Caml-list] Naming conventions
> 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?

I don't think there's a convention.  Part of the reason is that it
tends to be manifest in the type whether or not an operation is
destructive and whether or not it is a predicate.  Consider:

  val push : 'a -> 'a stack -> 'a stack  (* functional *)


  val push : 'a -> 'a stack -> unit        (* imperative *)

That's not to say that it wouldn't be good to have a convention,
especially when something has an interface that looks functional
but does some observable side effect.  Furthermore, it's often
hard to tell constructors from predicates when reading code
(i.e., does "empty" construct an empty stack or is it a predicate
that returns true on an empty stack?) 

I tend to use imp_<id> (as in imp_push) to reflect the fact that 
something imperative is going on, and is_<id> for predicates
(as in is_empty).  

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: