Version française
Home     About     Download     Resources     Contact us    
Browse thread
Private types in 3.11, again
[ 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: Re: [Caml-list] Private types in 3.11, again
Hi again,

I ditched the regular variants in favour of polymorphic variants, hoping
the coercion trick described by Jacques Garrigue would help [1].  I've also
simplified the formulation as much as possible.  Anyway, I'm still stuck
with the same problem: while function 'sprint' works alright inside the
Node module, its clone 'sprint2' fails to compile when placed outside.
Is this a case where no amount of explicit annotations and coercions will
work or am I missing something obvious?

Thanks in advance!
Regards,
Dario Teixeira

[1] http://groups.google.com/group/fa.caml/msg/855011402f1ca1b5


module Node:
sig
	type elem_t = [ `Text of string | `Bold of elem_t list ]
	type +'a t = private elem_t

	val text: string -> [> `Basic ] t
	val bold: 'a t list -> [> `Complex ] t
	val sprint: 'a t -> string
end =
struct
	type elem_t = [ `Text of string | `Bold of elem_t list ]
	type +'a t = elem_t

	let text str = `Text str
	let bold seq = `Bold seq
	let rec sprint = function
		| `Text str	-> Printf.sprintf "(Text %s)" str
		| `Bold seq	-> Printf.sprintf "(Bold %s)" (List.fold_left (^) "" (List.map sprint seq))
end


module Foobar:
sig
	val sprint2: 'a Node.t -> string
end =
struct
	let rec sprint2 node = match (node : _ Node.t :> [> ]) with
		| `Text str	-> Printf.sprintf "(Text %s)" str
		| `Bold seq	-> Printf.sprintf "(Bold %s)" (List.fold_left (^) "" (List.map sprint2 (seq : _ Node.t list :> [>] list)))
end