[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-08-06 (01:03) |
From: | SooHyoung Oh <shoh@d...> |
Subject: | Re: [Caml-list] Weak type, Open type |
Thanks for you reply. Fortunately, I'm using Ocaml 3.05 and polymophic method works well. But coding as your comments on weak type makes an error. See followings. > From: "SooHyoung Oh" <shoh@duonix.com> > > > While I've studying design pattern with ocaml, > > I made the followding 3 classes (PART1): > > (1) class virtual entry: base class > > (2) class file: subclass of "entry" class > > (3) class dir: subclass of "entry" class > > > > I made some code using these classes on top level and it's ok. (PART 2). > > While I translate the top level code into new class definition (PART3), it > > makes some error. > > The error message is on (PART 4). > > > > It seems that (PART2) is weak type and (PART 3) is open type. > > Not weak: file_list has a weak type variable, but it gets immediatly > instanciated to entry; and add is really polymorphic. > > > [Q 1] Is (PART2) is correct? I don't know why it doesn't make type error. > Yes. What's wrong? > Note that your #entry is meaningless, since it is immediatly > instanciated to entry. You could as well write entry list from the > beginning, or nothing at all. > The types of (PART2) are val file_list : _#entry list ref = {contents = []} val add : #entry -> unit = <fun> After removing '#': val file_list : entry list ref = {contents = []} val add : _#entry -> unit = <fun> Using "entry" instead of "#entry" produces the following: This expression has type file = < file_size : unit -> int; name : unit -> string > but is here used with type < dir_size : unit -> int; name : unit -> string > Only the second object type has a method dir_size [Deleted ...] ------------------- 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