caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* How do I abstract out polymorphic variants via functors?
@ 2006-08-18 13:35 Jacques Carette
  2006-08-19 14:51 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Jacques Carette @ 2006-08-18 13:35 UTC (permalink / raw)
  To: caml-list

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
module type TRACKPIVOT = sig
  type 'a lstate
  type 'a tag_lstate = [`TPivot of 'a lstate ]
  type ('b,'v) lm = ('a,'v,'s,'w) cmonad
    constraint 's = [> 'a tag_lstate]
    constraint 'b = 'a * 's * 'w
 ...
end

[I realize that I will have to lose the RANK type's definition of 'a 
lstate when I abstract this out]
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?

Jacques


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] How do I abstract out polymorphic variants via functors?
  2006-08-18 13:35 How do I abstract out polymorphic variants via functors? Jacques Carette
@ 2006-08-19 14:51 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2006-08-19 14:51 UTC (permalink / raw)
  To: carette; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-08-19 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-18 13:35 How do I abstract out polymorphic variants via functors? Jacques Carette
2006-08-19 14:51 ` [Caml-list] " Jacques Garrigue

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).