Version française
Home     About     Download     Resources     Contact us    
Browse thread
Merging object signatures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dario Teixeira <darioteixeira@y...>
Subject: Merging object signatures
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