caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] extend object type?
@ 2017-02-10 16:43 Steffen Smolka
  0 siblings, 0 replies; 5+ messages in thread
From: Steffen Smolka @ 2017-02-10 16:43 UTC (permalink / raw)
  To: Leo White, Caml List

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

Thanks, this will do! The #t1 syntax is something else I was looking for.

-- Steffen



> 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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extend object type?
@ 2017-02-10 14:49 Hongbo Zhang (BLOOMBERG/ 731 LEX)
  0 siblings, 0 replies; 5+ messages in thread
From: Hongbo Zhang (BLOOMBERG/ 731 LEX) @ 2017-02-10 14:49 UTC (permalink / raw)
  To: leo; +Cc: caml-list, garrigue

[-- 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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extend object type?
  2017-02-10  4:15 Steffen Smolka
  2017-02-10  8:30 ` Kakadu
@ 2017-02-10  9:42 ` Leo White
  1 sibling, 0 replies; 5+ messages in thread
From: Leo White @ 2017-02-10  9:42 UTC (permalink / raw)
  To: caml-list

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

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: 1273 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extend object type?
  2017-02-10  4:15 Steffen Smolka
@ 2017-02-10  8:30 ` Kakadu
  2017-02-10  9:42 ` Leo White
  1 sibling, 0 replies; 5+ messages in thread
From: Kakadu @ 2017-02-10  8:30 UTC (permalink / raw)
  To: Steffen Smolka; +Cc: Caml List

AFAIK it is not possible

https://github.com/ocamllabs/compiler-hacking/wiki/Things-to-work-on#support-extending-existing-object-types

Happy hacking,
Kakadu

On Fri, Feb 10, 2017 at 7:15 AM, Steffen Smolka <smolka@cs.cornell.edu> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Caml-list] extend object type?
@ 2017-02-10  4:15 Steffen Smolka
  2017-02-10  8:30 ` Kakadu
  2017-02-10  9:42 ` Leo White
  0 siblings, 2 replies; 5+ messages in thread
From: Steffen Smolka @ 2017-02-10  4:15 UTC (permalink / raw)
  To: caml-list

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

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: 353 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-10 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 16:43 [Caml-list] extend object type? Steffen Smolka
  -- strict thread matches above, loose matches on Subject: below --
2017-02-10 14:49 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-02-10  4:15 Steffen Smolka
2017-02-10  8:30 ` Kakadu
2017-02-10  9:42 ` Leo White

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).