caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.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 20:26:42 +0100	[thread overview]
Message-ID: <20110221192642.GK25151@localhost> (raw)
In-Reply-To: <982043.53335.qm@web111502.mail.gq1.yahoo.com>

Le Monday 21 Feb 2011 à 10:42:43 (-0800), Dario Teixeira a écrit :
> Hi,
> 
> > But I think that you will not be able to do such type narrowing in a
> > module interface / module interface fashion. At least not without an
> > indication of covariance or contravariance. And even then, I'm not sure
> > if that is possible.
> 
> Perhaps I am indeed pushing the module language beyond its design
> intentions, but my requirement does not strike me as completely
> unreasonable...
> 
> If I get rid of the constraint altogether, then I lose the guarantee that
> kind_t is a subtype of Kind.t.  But if I declare kind_t = Kind.t in the
> signature FOO, then I lose the ability to declare particular instances
> of FOO to be more *tightly* constrained than the generic Kind.t.
> 
> Any further ideas on how I may be able to have my cake and eat it too?
> 
> Cheers,
> Dario Teixeira

I think it's going to be tough. The closest I've come to is:

# module type Q = sig type 'a t end;;
module type Q = sig type 'a t end
# module type W = Q with type 'a t = [< `A | `B] as 'a;;
Error: In this `with' constraint, the new definition of t
       does not match its original definition in the constrained
signature:
       Type declarations do not match:
         type 'a t = 'a constraint 'a = [< `A | `B ]
       is not included in
         type 'a t
       Their constraints differ.

While it is possible to 'specialise' a type in a module type signature,
it seems unlikely that it is possible to 'specialise' constraints to
narrower constraints.


-- 
     Guillaume Yziquel


  reply	other threads:[~2011-02-22  7:14 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 [this message]
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=20110221192642.GK25151@localhost \
    --to=guillaume.yziquel@citycable.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;
as well as URLs for NNTP newsgroup(s).