caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Pierre Weis <pierre.weis@inria.fr>
Cc: brogoff@speakeasy.net, caml-list@inria.fr
Subject: Re: [Caml-list] syntax of private constructors in CVS version
Date: Thu, 03 Jul 2003 21:46:19 +1000	[thread overview]
Message-ID: <3F04178B.6050107@ozemail.com.au> (raw)
In-Reply-To: <200306301839.UAA20778@pauillac.inria.fr>

Pierre Weis wrote:


> As you should already know, usual sum and product types in Caml
> correspond to the mathematical notion of free algebraic data
> structures. This is fairly useful and allows the modelization of a lot
> of common data structures in practical programming
> situations. However, besides the free algebra structures,
> mathematicians use a lot of non-free algebras (so-called structures
> defined via generators and relations). Private types aim at giving a
> way to modelize those non-free structures. Equivalenetly, you can
> think of private types as providing a way to implement types equipped
> with invariants, quotient structures (i.e. sets of equivalence classes
> for some equivalence relation on a free algebra), or data types with
> canonical normal forms.


Well said. If I may add: this can already be done using

classes, or abstraction of modules. However these tools
are much *too* heavyweight, because they also hide the
algebraic structure of the types completely.

The user then must provide all the accessor functions,
for example, instead of using record labels or pattern matching.

For immutable values, establishing an invariant at construction

time is enough to ensure the invariant is preserved: therefore,
it is enough to make construction abstract to ensure all values
of the type satisfy the invariants.

Just for interest, this is not the case for mutable objects,

for example:

	type rational = private { mutable x: float; mutable y: float };
	...
	let mess_up_invariant (z:rational) = z.y <- 0.0

Be interested to know the treatment of records with mutable fields.
Are they permitted? Or are the mutators disallowed?

> In conclusion: private types serve to modelize types with arbitrary
> algebraic invariants (no miracle here: you must program those
> invariants in the definition of the constructing functions).
> 
> In contrast with abstract data types, the private types still maintain
> the elegant pattern matching facility of ML outside the module that
> defines the type.
> 
> Hope this helps.


Indeed, a fine dissertation, and a good choice for an extension

as well. Thanks!

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


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


  parent reply	other threads:[~2003-07-03 11:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-27 20:50 Shaddin Doghmi
2003-06-27 21:15 ` brogoff
2003-06-27 22:10   ` Shaddin Doghmi
2003-06-28  2:24     ` brogoff
2003-06-30 18:39       ` Pierre Weis
2003-06-30 19:00         ` Chris Hecker
2003-06-30 21:36           ` brogoff
2003-07-01 10:47           ` Pierre Weis
2003-07-01  7:43         ` Hendrik Tews
2003-07-01 10:37         ` Yaron M. Minsky
2003-07-01 10:51         ` Yaron M. Minsky
2003-07-01 17:05           ` Pierre Weis
2003-07-01 17:20             ` brogoff
2003-07-03 11:46         ` John Max Skaller [this message]
2003-07-07 22:31           ` Pierre Weis
2003-07-13  9:11             ` John Max Skaller
2003-07-15  8:02               ` Laurent Vibert
2003-07-15  8:22                 ` Pierre Weis

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=3F04178B.6050107@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=pierre.weis@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;
as well as URLs for NNTP newsgroup(s).