Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Krishnaswami, Neel" <neelk@cswcasa.com>
To: "Caml Mailing List (E-mail)" <caml-list@inria.fr>
Subject: Re: [Caml-list] Naming conventions
Date: Wed, 8 May 2002 09:33:03 -0400	[thread overview]
Message-ID: <B1E4D3274D57D411BE8400D0B783FF32A8D754@exchange1.cswv.com> (raw)

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


             reply	other threads:[~2002-05-08 13:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-08 13:33 Krishnaswami, Neel [this message]
2002-05-08 13:59 ` Dave Mason
2002-05-08 17:12   ` Pierre Weis
  -- strict thread matches above, loose matches on Subject: below --
2002-05-08 13:31 Gregory Morrisett
2002-05-08 13:10 Paul Stodghill
2002-05-08 14:04 ` Ken Wakita

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B1E4D3274D57D411BE8400D0B783FF32A8D754@exchange1.cswv.com \
    --to=neelk@cswcasa.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox