caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Recursive subtyping issue
@ 2010-02-27  1:52 Guillaume Yziquel
  2010-02-27  6:38 ` [Caml-list] " Andreas Rossberg
  0 siblings, 1 reply; 22+ messages in thread
From: Guillaume Yziquel @ 2010-02-27  1:52 UTC (permalink / raw)
  To: OCaml List

Hello.

I've been struggling to have a type system where I could do the 
following subtyping:

'a t1 :> t2  and  t2 :> 'a t1

So I've tried to do the following:

> yziquel@seldon:~$ ocaml
>         Objective Caml version 3.11.2
> 
> # #rectypes;;
> # module Q = struct
>     type -'a e
>     type 'a q = private w
>     and w = w e
>     and 'a r = 'a q e
>   end;;
> module Q :
>   sig type -'a e type 'a q = private w and w = w e and 'a r = 'a q e end

It almost seems to work:

> # let f x = (x : Q.w Q.e :> 'a Q.q Q.e);;
> val f : Q.w Q.e -> 'a Q.q Q.e = <fun>
> # let f' x = (x : Q.w :> 'a Q.r);;
> val f' : Q.w -> 'a Q.r = <fun>
> # let g x = (x : 'a Q.q :> Q.w);;
> val g : 'a Q.q -> Q.w = <fun>

We can subtype from 'a Q.q to Q.w and from Q.w to 'a Q.r. So I now only 
need to equate 'a Q.r with 'a Q.q in one way or another...

I therefore tried the following, unsuccessfully:

> # module W = struct
>     type -'a e = ('a -> unit) q
>     and 'a q = private w
>     and w = w e
>     and 'a r = 'a q e
>   end;;
> Error: The type abbreviation q is cyclic
> # 

What's going wrong? And how can one get to do the proposed recursive 
subtyping?

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


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

end of thread, other threads:[~2010-03-02 10:22 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-27  1:52 Recursive subtyping issue Guillaume Yziquel
2010-02-27  6:38 ` [Caml-list] " Andreas Rossberg
2010-02-27 10:25   ` Guillaume Yziquel
2010-02-27 11:49     ` Goswin von Brederlow
2010-02-27 13:11       ` Guillaume Yziquel
2010-02-27 16:52         ` Andreas Rossberg
2010-02-27 18:10           ` Guillaume Yziquel
2010-02-27 19:52             ` Guillaume Yziquel
2010-02-27 20:32               ` Guillaume Yziquel
2010-03-01 10:55                 ` Stéphane Glondu
2010-03-01 11:21                   ` Guillaume Yziquel
2010-03-01 12:28                     ` Stéphane Glondu
2010-03-01 12:49                       ` David Allsopp
2010-03-01 13:06                       ` Guillaume Yziquel
2010-03-01 12:49                     ` David Allsopp
2010-03-01 13:28                       ` Goswin von Brederlow
2010-03-01 20:12                         ` David Allsopp
2010-03-02 10:22                           ` Goswin von Brederlow
2010-03-01 13:33                       ` Guillaume Yziquel
2010-03-01 20:18                         ` David Allsopp
2010-02-28  9:54         ` Goswin von Brederlow
2010-02-28 11:08           ` Guillaume Yziquel

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