caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Merging object signatures
@ 2010-11-04 18:55 Dario Teixeira
  2010-11-04 20:01 ` [Caml-list] " Goswin von Brederlow
  0 siblings, 1 reply; 5+ messages in thread
From: Dario Teixeira @ 2010-11-04 18:55 UTC (permalink / raw)
  To: caml-list

Hi,

Similarly to polymorphic variants, is there a way for object signatures to
be merged by type name?  Consider the example at the end; I'm wondering if
it is possible for the declaration of 'foobar' to be something along the
lines of 'val foobar: int -> int -> < foo_t; bar_t >' instead of needing to
explicitly list all the methods in foo_t and bar_t.

Thanks in advance for your help!
Best regards,
Dario Teixeira


module Test:
sig
	type foo_t = < a: int >
	type bar_t = < b: int >

	val foobar: int -> int -> < a:int; b: int >

	(* val foobar: int -> int -> < foo_t; bar_t > *)
end =
struct
	type foo_t = < a: int >
	type bar_t = < b: int >

	class foo a = object method a: int = a end
	class bar b = object method b: int = b end

	let foobar a b =
	object
		inherit foo a
		inherit bar b
	end
end






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

* Re: [Caml-list] Merging object signatures
  2010-11-04 18:55 Merging object signatures Dario Teixeira
@ 2010-11-04 20:01 ` Goswin von Brederlow
  2010-11-05 12:58   ` Dario Teixeira
  0 siblings, 1 reply; 5+ messages in thread
From: Goswin von Brederlow @ 2010-11-04 20:01 UTC (permalink / raw)
  To: Dario Teixeira; +Cc: caml-list

Dario Teixeira <darioteixeira@yahoo.com> writes:

> Hi,
>
> Similarly to polymorphic variants, is there a way for object signatures to
> be merged by type name?  Consider the example at the end; I'm wondering if
> it is possible for the declaration of 'foobar' to be something along the
> lines of 'val foobar: int -> int -> < foo_t; bar_t >' instead of needing to
> explicitly list all the methods in foo_t and bar_t.
>
> Thanks in advance for your help!
> Best regards,
> Dario Teixeira
>
>
> module Test:
> sig
> 	type foo_t = < a: int >
> 	type bar_t = < b: int >
>
> 	val foobar: int -> int -> < a:int; b: int >
>
> 	(* val foobar: int -> int -> < foo_t; bar_t > *)
> end =
> struct
> 	type foo_t = < a: int >
> 	type bar_t = < b: int >
>
> 	class foo a = object method a: int = a end
> 	class bar b = object method b: int = b end
>
> 	let foobar a b =
> 	object
> 		inherit foo a
> 		inherit bar b
> 	end
> end

Can't you make foo_t and bar_t class types and foobar_t inherits them
both?

MfG
        Goswin


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

* Re: [Caml-list] Merging object signatures
  2010-11-04 20:01 ` [Caml-list] " Goswin von Brederlow
@ 2010-11-05 12:58   ` Dario Teixeira
  2010-11-05 14:45     ` Jacques Garrigue
  0 siblings, 1 reply; 5+ messages in thread
From: Dario Teixeira @ 2010-11-05 12:58 UTC (permalink / raw)
  To: Goswin von Brederlow; +Cc: caml-list

Hi,

> Can't you make foo_t and bar_t class types and foobar_t inherits them
> both?

Thanks for the reply.  Yes, in the toy example I posted that would indeed
be an alternative.  Still, I'm wondering about the most general case;
suppose I had a function that took an object satisfying both foo_t and bar_t:

val do_something: < foo_t; bar_t; .. > -> bool

This is what I'm wondering if it's possible to express.

Best regards,
Dario Teixeira






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

* Re: [Caml-list] Merging object signatures
  2010-11-05 12:58   ` Dario Teixeira
@ 2010-11-05 14:45     ` Jacques Garrigue
  2010-11-05 17:58       ` Dario Teixeira
  0 siblings, 1 reply; 5+ messages in thread
From: Jacques Garrigue @ 2010-11-05 14:45 UTC (permalink / raw)
  To: Dario Teixeira; +Cc: caml-list

On 2010/11/05, at 21:58, Dario Teixeira wrote:
>> Can't you make foo_t and bar_t class types and foobar_t inherits them
>> both?
> 
> Thanks for the reply.  Yes, in the toy example I posted that would indeed
> be an alternative.  Still, I'm wondering about the most general case;
> suppose I had a function that took an object satisfying both foo_t and bar_t:
> 
> val do_something: < foo_t; bar_t; .. > -> bool
> 
> This is what I'm wondering if it's possible to express.

Same thing:

  class type foobar_t = object inherit foo_t inherit bar_t end
  val do_something : #foobar_t -> bool

I agree that this is rather verbose.
I thought a few times of adding the syntax you propose, but was always
stopped by the fact you can already do it in a verbose way.

Jacques Garrigue

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

* Re: [Caml-list] Merging object signatures
  2010-11-05 14:45     ` Jacques Garrigue
@ 2010-11-05 17:58       ` Dario Teixeira
  0 siblings, 0 replies; 5+ messages in thread
From: Dario Teixeira @ 2010-11-05 17:58 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

Hi,

>   class type foobar_t = object inherit foo_t inherit bar_t end
>   val do_something : #foobar_t -> bool
> 
> I agree that this is rather verbose. I thought a few times of adding the
> syntax you propose, but was always stopped by the fact you can already do
> it in a verbose way.

Actually, I was unaware that the '#' syntax could also be used for objects,
though in retrospect it does make sense given how its used with polymorphic
variants.  And verboseness notwithstanding, the code above does solve my
problem nicely -- thanks!

Best regards,
Dario Teixeira






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

end of thread, other threads:[~2010-11-05 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-04 18:55 Merging object signatures Dario Teixeira
2010-11-04 20:01 ` [Caml-list] " Goswin von Brederlow
2010-11-05 12:58   ` Dario Teixeira
2010-11-05 14:45     ` Jacques Garrigue
2010-11-05 17:58       ` Dario Teixeira

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