Browse thread
Smells like duck-typing
- Dario Teixeira
[
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: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] Re: Smells like duck-typing |
From: "William D. Neumann" <wneumann@cs.unm.edu> > On Thu, 18 Oct 2007 18:13:05 +0200, Zheng Li wrote > > > Strangely though, there seems to be a bug in the OO type system: > > (The solution proposed above is safe, as it does coercion) > > > > # let coredump = object inherit templt end;; > > val coredump : templt = <obj> > > # coredump#title;; > > > > Process caml-toplevel segmentation fault > > Hmmm... interesting. You can apparently create immediate objects with > virtual instance variables, so long as you don't have virtual methods. > > Objective Caml version 3.10.0 > > # let bad = object method virtual ooops : int end;; > Characters 10-47: > let bad = object method virtual ooops : int end;; > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > This class should be virtual. The following methods are undefined : ooops > # let bad_int = object val virtual x : int method get_x = x end;; > val bad_int : < get_x : int > = <obj> > # let bad_str = object val virtual x : string method get_x = x end;; > val bad_str : < get_x : string > = <obj> > # bad_int # get_x;; > - : int = 0 > # bad_str # get_x;; Virtual fields are a new and experimental feature in 3.10. The above bug was fixed shortly after the release. Jacques Garrigue