caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus@oefai.at>
To: Nicolas FRANCOIS <nicolas.francois@free.fr>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] About modules again
Date: Mon, 15 Jul 2002 10:44:35 +0200	[thread overview]
Message-ID: <20020715084435.GA31562@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <20020715023542.56e961fa.nicolas.francois@free.fr>

On Mon, 15 Jul 2002, Nicolas FRANCOIS wrote:
> (it's an Euclidian Ring, but that's not the point). So you see my problem
> : I have to define a concrete method in an abstract module, just not to
> have to fill the definition for every new Ring I define.
> 
> Is there a way to do this ? Or is this specific to objects ?

This is the point where higher-order modules (functors) enter the game.
If you have some common functionality that is shared across all rings,
you can factor it out in a functor body. E.g.:

  module MakeRing (Spec : RING_SPEC) : RING = struct
    include Spec

    (* All common stuff follows here *)
  end

Module "Spec" should adhere to a signature "RING_SPEC", the latter
specifying what is different or at least parameterizable for each
ring. Applying the functor to such a specification yields a module that
implements the signature RING, e.g.:

  module Ring_Z = MakeRing (Ring_Z_Spec)

The specification of rings over Z (Ring_Z_Spec) may itself be the result
of a functor application. This way you can highly modularize the creation
of algebraic structures.

Btw., you'd surely get into troubles using OO here. It is not very
suitable for such purposes, because it lacks expressiveness if you want
to specify interaction of several types (sorts) at an abstract level.

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
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-07-15  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15  0:35 Nicolas FRANCOIS
2002-07-15  8:44 ` Markus Mottl [this message]
2002-07-16  9:59   ` Nicolas FRANCOIS

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=20020715084435.GA31562@fichte.ai.univie.ac.at \
    --to=markus@oefai.at \
    --cc=caml-list@inria.fr \
    --cc=nicolas.francois@free.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).