Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Width subtyping
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Re: [Caml-list] Width subtyping
There must be something that escapes me.... This seems to be an
example where ocaml objects really shine because of the structural
typing (i.e. an object is defined by the its structure):

type t1 = <a: int; b: int; c: int; >
type t2 = <a: int; b: int; c: int; d: int >
type t3 = <        b: int; c: int; d: int >

let v1 : t1 = object method a = 1; method b = 2; method c =3 end
let v2 : t2 = object method a = 1; method b = 2; method c =3 ; method d = 4 end
let v3 : t3 = object method b = 2; method c =3 ; method d = 4 end

let get_a x : int = x#a

let _ = get_a v1 (** ok*)
let _ = get_a v2 (** ok *)
let _ = get_a v3 (** rejected by the type checker*)

On Fri, May 29, 2009 at 11:45 AM, Dario Teixeira
<darioteixeira@yahoo.com> wrote:
>
> Hi,
>
>> The dual of sums is products.  Open (labelled) sums
>> are "polymorphic variants".  Their duals are open
>> (labelled) products are "rows" (which O'Caml already
>> supports, through its objects).
>
> Yes, as I mentioned, for some classes of this particular problem the object
> system can be put to good use -- when there is a clear tree for inheritance,
> for example.  Unfortunately that is always not the case; there are problems
> where you would end up with a tangled web of multiple inheritances just for
> the sake of avoiding duplicating methods.
>
> Cheers,
> Dario
>
>
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>