English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2010-11-04 (18:55)
From: Dario Teixeira <darioteixeira@y...>
Subject: Merging object signatures

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:
	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 =
	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 =
		inherit foo a
		inherit bar b