From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Constraining abstract type to be of a given subtype
Date: Mon, 21 Feb 2011 22:31:05 +0100 [thread overview]
Message-ID: <AANLkTi=8Jw8Zvndm2duQy-=dREwLXZA_Y45E-yeDOye0@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinzYLBzCGB6hKdW+ArOHO901q5j_SmBtNm=NsYf@mail.gmail.com>
> In fact it does compile but I don't think it does what you want
> because the 'a is completly unrelated to the `A in Foo1.kind_t
Oh well it's always the same error : when you are doing phantom types,
the type with phantoms should be abstract. See below.
Daniel
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 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
val kind_to_kind : 'a kind_t -> Kind.t
end
module Foo1 : sig
type custom_t
type 'a kind_t constraint 'a = [< Kind.t]
type 'a t = int * custom_t * 'a kind_t
val make_custom : float -> custom_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
val kind_of_kind : ([ `A ] as 'a) -> 'a kind_t
val kind_to_kind : 'a kind_t -> Kind.t
end = struct
type custom_t = float
type 'a kind_t = [`A] constraint 'a = [< Kind.t]
type 'a t = int * custom_t * 'a kind_t
let make_custom f = f
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)
let kind_of_kind k = k
let kind_to_kind k = (k :> Kind.t)
end
let (v : [`A] Foo1.t) =
Foo1.make 2 (Foo1.make_custom 2.) (Foo1.kind_of_kind `A)
(* Should not typecheck
let (v : [`B] Foo1.t) =
Foo1.make 2 (Foo1.make_custom 2.) (Foo1.kind_of_kind `A)
*)
module FOOCheck = (Foo1 : FOO)
next prev parent reply other threads:[~2011-02-21 21:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 15:56 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 [this message]
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='AANLkTi=8Jw8Zvndm2duQy-=dREwLXZA_Y45E-yeDOye0@mail.gmail.com' \
--to=daniel.buenzli@erratique.ch \
--cc=caml-list@inria.fr \
--cc=darioteixeira@yahoo.com \
/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