caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: carette@mcmaster.ca
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How do I abstract out polymorphic variants via functors?
Date: Sat, 19 Aug 2006 23:51:34 +0900 (JST)	[thread overview]
Message-ID: <20060819.235134.94072006.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <44E5C226.3030802@mcmaster.ca>

From: Jacques Carette <carette@mcmaster.ca>
Subject: [Caml-list] How do I abstract out polymorphic variants via functors?
Date: Fri, 18 Aug 2006 09:35:34 -0400

> I have 3 module types, each of which start out "the same", viz:
> module type DETERMINANT = sig
>   type 'a lstate
>   type 'a tag_lstate = [`TDet of 'a lstate ]
>   type ('b,'v) lm = ('a,'v,'s,'w) cmonad
>     constraint 's = [> 'a tag_lstate]
>     constraint 'b = 'a * 's * 'w
>   ...
> end
> module type RANK = sig
>   type 'a lstate = ('a, int ref) code
>   type 'a tag_lstate = [`TRan of 'a lstate ]
>   type ('b,'v) lm = ('a,'v,'s,'w) cmonad
>     constraint 's = [> 'a tag_lstate]
>     constraint 'b = 'a * 's * 'w
>   ...
> end
[...]
> The only thing different between those 3 is the name of the polymorphic 
> variant - so clearly an opportunity for abstraction!  But I can't seem 
> to achieve this.  Is there a way?

Not currently.
The problem is that [> 'a tag_lstate] is only defined when tag_lstate
has a concrete definition. So if you abstract tag_lstate, you cannot
keep this constraint. Private row types won't help either, since they
can only be implemented by structurally monomorphic types. So I see no
way out, at least with this encoding. Another approach might be to add
variance annotations, and use subtyping rather than polymorphism (but
I don't know whether it makes sense here.)

Jacques Garrigue


      reply	other threads:[~2006-08-19 15:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-18 13:35 Jacques Carette
2006-08-19 14:51 ` Jacques Garrigue [this message]

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=20060819.235134.94072006.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=carette@mcmaster.ca \
    /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).