caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: YAMAGATA yoriyuki <yoriyuki@mbg.sphere.ne.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Five Questions about Objects
Date: Sun, 14 Jul 2002 09:58:16 +0900	[thread overview]
Message-ID: <20020714095816B.yoriyuki@mbg.sphere.ne.jp> (raw)
In-Reply-To: <200207131340.JAA07158@hickory.cc.columbia.edu>

From: Oleg <oleg_inconnu@myrealbox.com>
Subject: [Caml-list] Five Questions about Objects
Date: Sat, 13 Jul 2002 09:42:47 -0400

> let point a b = 
>   object
>     val x = a
>     val y = b
>     method get () = (x, y)
>   end;;

I think You can't do like this.  object ... end is a part of a class
definition, and not an ordinary expression.

However, I wonder why a class is necessary in the first place.  I'm
not familiar with the theory of OOP, but I feel like direct creation
of objects is possible in functional languages.  It simplifies the
syntax, fits better the concept of functional programming, (I mean
the slogan that everything is an expression.) and more powerful.  Ok,
maybe it does not have much advantage over current approach, but if
both can do the same thing, why not use the simpler one?

> 4) Can I construct an object that the following function f would accept?
> # let f a = a#m1 (); a#b#m2 ();;
> val f : < b : < m2 : unit -> 'a; .. >; m1 : unit -> 'b; .. > -> 'a = <fun>

# class ['b] b (v:'b) = object method m2 () = v end;;
class ['a] b : 'a -> object method m2 : unit -> 'a end
# class ['a, 'c] a (v1: 'c) (v2:'a b) = 
object method m1 () = v1 method b = v2 end;;
class ['a, 'b] a :
  'b -> 'a b -> object method b : 'a b method m1 : unit -> 'b end
# f (new a 0 (new b 0));;
- : int = 0

--
Yamagata Yoriyuki
http://www.mars.sphere.ne.jp/yoriyuki/
-------------------
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-14  2:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-13 13:42 Oleg
2002-07-14  0:58 ` YAMAGATA yoriyuki [this message]
2002-07-14  2:41   ` Brian Smith
2002-07-20 15:46     ` YAMAGATA yoriyuki
2002-07-14  8:58   ` Alain Frisch
2002-07-14  9:38     ` Jacques Garrigue
2002-07-14 10:23       ` William Lovas
2002-07-14  3:26 ` Jacques Garrigue
2002-07-14 15:47 ` Xavier Leroy
2002-07-16  4:48   ` Oleg
2002-07-16  4:49   ` Oleg

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=20020714095816B.yoriyuki@mbg.sphere.ne.jp \
    --to=yoriyuki@mbg.sphere.ne.jp \
    --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).