caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Constraining abstract type to be of a given subtype
@ 2011-02-21 15:56 Dario Teixeira
  2011-02-21 17:07 ` Guillaume Yziquel
  0 siblings, 1 reply; 10+ messages in thread
From: Dario Teixeira @ 2011-02-21 15:56 UTC (permalink / raw)
  To: caml-list

Hi,

In a signature FOO, I'm trying to constrain an abstract type kind_t to be a
subtype of Kind.t (please see code below).  However, I get a compiler error
when I declare an actual struct Foo1 which supposedly obeys signature FOO:

  Type declarations do not match:
    type 'a kind_t = [ `A ]
  is not included in
    type 'a kind_t = 'a constraint 'a = [< Kind.t ]


Any hints as to what is wrong here?  Thanks in advance for your help!

Best regards,
Dario Teixeira


module Kind:
sig
	type t = [ `A | `B | `C ]

	val to_string: t -> string
end =
struct
	type t = [ `A | `B | `C ]

	let to_string = function
		| `A -> "A"
		| `B -> "B"
		| `C -> "C"
end


module type FOO =
sig
	type custom_t
	type 'a kind_t = 'a constraint 'a = [< Kind.t ]
	type 'a t = int * custom_t * 'a kind_t

	val make: int -> custom_t -> 'a kind_t -> 'a t
	val string_of_custom: custom_t -> string
	val string_of_kind: 'a kind_t -> string
end


module Foo1: FOO =
struct
	type custom_t = float
	type 'a kind_t = [ `A ]
	type 'a t = int * custom_t * 'a kind_t

	let make id custom kind = (id, custom, kind)
	let string_of_custom = string_of_float
	let string_of_kind k = Kind.to_string (k :> Kind.t)
end



      


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

end of thread, other threads:[~2011-02-22 16:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-21 15:56 [Caml-list] Constraining abstract type to be of a given subtype Dario Teixeira
2011-02-21 17:07 ` Guillaume Yziquel
2011-02-21 18:42   ` Dario Teixeira
2011-02-21 19:26     ` Guillaume Yziquel
2011-02-21 19:39     ` Daniel Bünzli
2011-02-21 20:22       ` Dario Teixeira
2011-02-21 20:59         ` Daniel Bünzli
2011-02-21 21:31           ` Daniel Bünzli
2011-02-21 21:49             ` Daniel Bünzli
2011-02-22 16:15               ` 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).