From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@inria.fr
Subject: [Caml-list] Constraining abstract type to be of a given subtype
Date: Mon, 21 Feb 2011 07:56:43 -0800 (PST) [thread overview]
Message-ID: <241708.48122.qm@web111501.mail.gq1.yahoo.com> (raw)
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
next reply other threads:[~2011-02-21 15:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 15:56 Dario Teixeira [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=241708.48122.qm@web111501.mail.gq1.yahoo.com \
--to=darioteixeira@yahoo.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox