caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Hongbo Zhang (BLOOMBERG/ 731 LEX)" <hzhang295@bloomberg.net>
To: leo@lpw25.net
Cc: caml-list@inria.fr, garrigue@math.nagoya-u.ac.jp
Subject: Re: [Caml-list] extend object type?
Date: Fri, 10 Feb 2017 14:49:57 -0000	[thread overview]
Message-ID: <589DD31502F9008000390391_0_47973@msllnjpmsgsv06> (raw)

[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]

The syntax is a bit too heavy.
Note that structual typing is a killer feature for FFI with JS libraries,
it would be awesome if we could add some sugar to make below happen
type t1 = < f : int > 
type t2 = < ..t1 ; g : bool>
Is it possible to make it happen? Thanks -- Hongbo

From: leo@lpw25.net At: 02/10/17 04:42:52
To: caml-list@inria.fr
Subject: Re: [Caml-list] extend object type?

    
You can't do it for object types directly, but you can do it for class types:
 

 
  class type t1 = object method f : int end
 

 
  class type t2 = object inherit t1 method g : bool end
 

 
Defining a class type also defines the corresponding object type, which means the above results in types called t1 and t2 that are equal to the ones you want.
 

 
This trick also lets you use #t2 to refer to the polymorphic type < f : int; g : bool; .. >. 

 
Regards,
 

 
Leo 

 
On Thu, 9 Feb 2017, at 11:15 PM, Steffen Smolka wrote:
 
Is there syntax to conveniently extend object types?
 
Concretely, for types
 

 
type t1 = < f : int >
 
type t2 = < f : int; g : bool >
 

 
I would like a syntax that allows me to define t2 in terms of t1.
 

 
Thanks!
 
-- Steffen


  

[-- Attachment #2: Type: text/html, Size: 2979 bytes --]

             reply	other threads:[~2017-02-10 14:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 14:49 Hongbo Zhang (BLOOMBERG/ 731 LEX) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-02-10 16:43 Steffen Smolka
2017-02-10  4:15 Steffen Smolka
2017-02-10  8:30 ` Kakadu
2017-02-10  9:42 ` Leo White

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=589DD31502F9008000390391_0_47973@msllnjpmsgsv06 \
    --to=hzhang295@bloomberg.net \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    --cc=leo@lpw25.net \
    /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;
as well as URLs for NNTP newsgroup(s).