Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Till Varoquaux <till.varoquaux@gmail.com>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: Jacques Carette <carette@mcmaster.ca>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Width subtyping
Date: Fri, 29 May 2009 12:06:15 -0400	[thread overview]
Message-ID: <9d3ec8300905290906j675f6406je81420afdcc9473d@mail.gmail.com> (raw)
In-Reply-To: <407261.14507.qm@web111505.mail.gq1.yahoo.com>

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
>


  reply	other threads:[~2009-05-29 16:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-29 15:45 Dario Teixeira
2009-05-29 16:06 ` Till Varoquaux [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-06-01 13:56 Dario Teixeira
2009-06-01 14:21 ` David Allsopp
2009-06-01 17:04   ` Peng Zang
2009-05-31 23:08 Dario Teixeira
2009-06-01 11:34 ` Yaron Minsky
2009-05-30 15:36 Dario Teixeira
2009-05-31  5:18 ` Dave Benjamin
2009-05-31  7:34   ` David Allsopp
2009-06-01  4:21   ` Jacques Garrigue
2009-05-29 15:50 Dario Teixeira
2009-05-29 15:38 Dario Teixeira
2009-05-29 14:10 Dario Teixeira
2009-05-29 14:21 ` [Caml-list] " Jacques Carette
2009-05-29 14:43 ` David Allsopp
2009-05-29 15:33 ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d3ec8300905290906j675f6406je81420afdcc9473d@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=carette@mcmaster.ca \
    --cc=darioteixeira@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox