Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Five Questions about Objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: YAMAGATA yoriyuki <yoriyuki@m...>
Subject: Re: [Caml-list] Five Questions about Objects
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