From: "Mattias Waldau" <mattias.waldau@abc.se>
To: <caml-list@inria.fr>
Subject: RE: Real excellent object oriented source code examples of Ocaml
Date: Sun, 19 Nov 2000 16:48:52 +0100 [thread overview]
Message-ID: <HDEEKOMJILGEIHIMAPCDAEHIDKAA.mattias.waldau@abc.se> (raw)
In-Reply-To: <0C682B70CE37BC4EADED9D375809768A48FC72@red-msg-04.redmond.corp.microsoft.com>
The reason I don't use the OO-features is not because I don't like OO, but
since Ocaml support for OO isn't as good as it could be.
The OO-features are just built on top of the normal environment. For
example, the toplevel don't understand objects, you just get the message "-
: with_oo = <obj>". The support for terms is much better. Thus, my
Caml-programs have the structure of OO, but I code them without the
OO-features of Ocaml. For example, I wouldn't normally write the
'with_oo'-class below, instead I code it as 'nooo' below.
However, if the support for showing/browsing objects on the toplevel would
be better (or maybe it is already there and I should just read the manual
better), I will start using OO in Ocaml.
The only problem with OO is that OO and functional programs don't mix well,
since OO is built on state-change. My background is from functionalal and
logic programming.
/mattias
P.s. How is the speed of methods calls, object creation compare to standard
calls and creating terms?
WITH OO:
========
class with_oo =
object
val mutable x = 0
val mutable y = 0
method get_x = x
method move d = x <- x + d; y <- y + d
end
(*
# let t = new with_oo;;
val t : with_oo = <obj>
# t;;
- : with_oo = <obj>
# t#get_x;;
- : int = 0
# t#move 10;;
- : unit = ()
# t#get_x;;
- : int = 10
#
*)
SAME CODE WITHOUT OO:
=====================
type nooo = {
mutable x:int;
mutable y:int;
}
let nooo_init =
{ x=0; y=0 }
let nooo_get_x this = this.x
let nooo_move this d =
this.x <- this.x + d;
this.y <- this.y + d
(*
# let t = nooo_init;;
val t : nooo = {x=0; y=0}
# nooo_get_x t;;
- : int = 0
# nooo_move t 10;;
- : unit = ()
# t;;
- : nooo = {x=10; y=10}
*)
next prev parent reply other threads:[~2000-11-20 19:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-17 14:38 Don Syme
2000-11-19 15:48 ` Mattias Waldau [this message]
-- strict thread matches above, loose matches on Subject: below --
2000-11-20 20:43 David McClain
2000-11-21 16:49 ` Brian Rogoff
2000-11-17 12:14 STARYNKEVITCH Basile
2000-11-20 13:46 ` Xavier Leroy
2000-11-23 19:32 ` Anton Moscal
2000-11-28 14:12 ` Renaud.Rioboo
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=HDEEKOMJILGEIHIMAPCDAEHIDKAA.mattias.waldau@abc.se \
--to=mattias.waldau@abc.se \
--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