Version française
Home     About     Download     Resources     Contact us    
Browse thread
Smells like duck-typing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William D. Neumann <wneumann@c...>
Subject: Re: [Caml-list] Re: Smells like duck-typing
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;;

*boom!*

--

William D. Neumann