caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "M E Leypold @ labnet" <leypold@informatik.uni-tuebingen.de>
To: mwohlwend@web.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] What are Classes for in O'Caml?
Date: Fri, 8 Nov 2002 20:59:45 +0100	[thread overview]
Message-ID: <15820.6065.703831.492860@hod.void.org> (raw)
In-Reply-To: <200211081445.29249.mwohlwend@web.de>



Michael Wohlwend writes:
 > On Freitag, 8. November 2002 14:24, Oleg wrote:

 > > I'm curious as to what classes are for in O'Caml (in view of the
 > > fact that it already has abstract data types) ?

 > Has somone found a *best* solution (for his tasks) to combine them
 > (classes und modules) or is it really just a matter of taste?


The following is only a suggestion:

  - Modules are units of compilation, hide away implemantation details
    and capsule namespaces.  In a sense they are 'compile-time
    constructs'.

  - ADT's -- just what you should use to represent your data. Always
    (well: almost) use abstractions, that is, hide representation
    details and make operations available only by procdures /
    functions. Strongly related ADTs (i.e. vectors and matrices) which
    need to know each others representation should go into one module,
    but not strongly related ADTs into different modules. Note, that
    ADTs are _values_.

  - Classes, well, let's talk about objects (in my book classes are
    only a method to get objects ...): Objects are storage for state.
    Note: an object might contain state A and later state B. Applying
    a similar sentence to the type list doesn't make sense: You have
    either list A (one value) or list B (another value). There is no
    later time: When the name get's bound, it becomes a symbol for
    that value until it goes out of scope [*]. 

    Objects make sense, when you want to have operations that do
    destruktive update (recycle the memory representation of their
    input to get the output). And this is useful to encapsule program
    external state (Printer, Filesystem, ...), where the old state is
    also lost after an operation [**]. 

Hope that makes sense to anyone.

 Regards -- Markus



[*] I know, ML has imperative features. I'm talking about funktional
programming here (pushing around _values_, not: "updating variables"
or "updating memory locations"). Object orientation (in a sense) is
really an imperative programming style :-).

[**] Mercury has a special 'unique' spezifier for this kind of values,
which pass into an operation and might not be referred to
afterwards. This way Mercury deals with state changes in the outside
world (I/O) in a purely functional way.
-------------------
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:[~2002-11-08 19:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-08 13:24 Oleg
2002-11-08 13:45 ` Michael Wohlwend
2002-11-08 13:57   ` Luc Maranget
2002-11-09 12:44     ` Didier Remy
2002-11-08 19:50   ` Chris Hecker
2002-11-08 19:59   ` M E Leypold @ labnet [this message]
2002-11-08 20:41     ` Brian Hurt
2002-11-09  2:54   ` brogoff

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=15820.6065.703831.492860@hod.void.org \
    --to=leypold@informatik.uni-tuebingen.de \
    --cc=caml-list@inria.fr \
    --cc=mwohlwend@web.de \
    /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).