* [Caml-list] Monadic classes
@ 2014-08-08 12:01 Christoph Höger
0 siblings, 0 replies; only message in thread
From: Christoph Höger @ 2014-08-08 12:01 UTC (permalink / raw)
To: caml users
-----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-----
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-08-08 12:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-08 12:01 [Caml-list] Monadic classes Christoph Höger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox