caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Constrained existential types
@ 2012-10-23 10:56 Romain Bardou
  2012-10-23 12:31 ` Leo P White
  0 siblings, 1 reply; 4+ messages in thread
From: Romain Bardou @ 2012-10-23 10:56 UTC (permalink / raw)
  To: caml-list

(This is the 4th time I send this e-mail because it does not seem to 
work. I'm trying with another SMTP server.)

Hello list,

I'm trying to use first-class modules to have existential types. But my 
existential type must be constrained. I have the following code:

type 'a t constraint 'a = [< `A | `B ]

module type SIG =
sig
   type a = private [< `A | `B ]
   val x: a t
end

let create (type u) (y: u t) =
   let module M: SIG =
     struct
       type a = u
       let x = y
     end
   in
   ()

It does not compile, because of the following error:

Error: This type u should be an instance of type [< `A | `B ]

In the manual I did not see any way to constrain type u. If I write 
something like this instead:

let create (y: 'a t) =
   let module M: SIG =
     struct
       type a = 'a
       let x = y
     end
   in
   ()

Then the definition "type a = 'a" is not correct, because 'a is not bound.

Is there any way to have constrained existential types?

Thanks,

-- 
Romain Bardou

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

end of thread, other threads:[~2012-10-23 13:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-23 10:56 [Caml-list] Constrained existential types Romain Bardou
2012-10-23 12:31 ` Leo P White
2012-10-23 12:35   ` Romain Bardou
2012-10-23 13:54   ` 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).