caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Monadic classes
Date: Fri, 08 Aug 2014 14:01:12 +0200	[thread overview]
Message-ID: <53E4BC08.4070109@tu-berlin.de> (raw)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

suppose, you have a state monad, i.e. a simple int counter:

let next s = (s+1, s) ;;

and now you want to make use of that state monad during class
construction:

class a s = let (s', _x) = next s in
            let (s'', _y) = next s' in
            object method x = _x ; method y = _y end ;;

class b s = let (s', _z) = next s in
            object method z = _z end ;;

What you can do, is single inheritance:

class c s = object inherit a s end ;;

(new c 2)#y ;; (* evaluates to: - : int = 3 *)


But to have a truly monadic class construction, I would have to
_return_ the state from the instantiated class and pass it on to the
second class, i.e. something like this:

class c s = object s' = inherit a s ; inherit b s' end ;;

Is something like this possible in OCaml?

regards,

Christoph

- -- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlPkvAgACgkQhMBO4cVSGS/JewCfStr70tNfURFeVA845HpZjkto
73AAoInnfnHaPtdbbMvCqNVY/yUwuQec
=duU4
-----END PGP SIGNATURE-----

                 reply	other threads:[~2014-08-08 12:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=53E4BC08.4070109@tu-berlin.de \
    --to=christoph.hoeger@tu-berlin.de \
    --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;
as well as URLs for NNTP newsgroup(s).