From: Jacques Carette <carette@mcmaster.ca>
To: caml-list@inria.fr
Subject: private types - suggestion
Date: Tue, 20 Jan 2009 11:43:29 -0500 [thread overview]
Message-ID: <4975FF31.90900@mcmaster.ca> (raw)
[See full code below]
I have encountered a fairly subtle issue with private types which
doesn't occur otherwise. The source of the issue, I believe, is
actually the need to have a 'row variable' available to be able to use
'private' on a polymorphic variant.
In the code below (a massive simplification of my actual case), f
compiles, but g does not, with error
Error: This pattern matches values of type
[> `Operator of 'a * 'b list * 'c S.pk ]
but is here used to match values of types S.operator
Types for tag `Operator are incompatible
(pointing to the line that starts with | `Operator ...)
First suggestion: could the error message please include what the
incompatibility is?
Second suggestion: could the type S.operator be (also) given in its
'expanded' form? It would be useful to know what the compiler thinks
the type S.operator actually is.
Third suggestion: in this particular case, could the error message
include some hints that the problem is one of [< ] vs [> ] ? [if my
understanding of the issue is correct!]
I will add these suggestions to the bug system next, but I figured
others on this list might benefit from my experience in debugging this
issue in my code.
Jacques
PS: I actually don't want the intermediate type pk, po, pb and ps to be
visible at all outside of S, but I do not know how to achieve that
without adding another layer of indirection. Any advice along these
lines would be appreciated.
PPS: I experimented with variance annotations too, thinking that that
might do the trick, but to no avail.
---
module S : sig
type 'a pk = KType | KFormula | Kind of 'a pb
and 'a po = [`Operator of string * 'a pk list * 'a pk ]
and 'a pb = [`Thing of string]
type 'a ps = ['a po | 'a pb]
type se = se ps
type operator = private [< se po]
end = struct
type 'a pk = KType | KFormula | Kind of 'a pb
and 'a po = [`Operator of string * 'a pk list * 'a pk ]
and 'a pb = [`Thing of string]
type 'a ps = ['a po | 'a pb]
type se = se ps
type operator = se po
end
open S
(* this one works *)
let f (o:operator) : string =
match o with
| `Operator(s, [], S.KType) -> s
| `Operator(_,_,_) -> failwith "nope"
(* this one doesn't ! *)
let g (o:operator) : string =
match o with
| `Operator(s, [], S.KType) -> s
| _ -> failwith "nope"
;;
reply other threads:[~2009-01-20 16:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4975FF31.90900@mcmaster.ca \
--to=carette@mcmaster.ca \
--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