English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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 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