Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type visibility limitation in recursive modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Peng Zang <peng.zang@g...>
Subject: Re: [Caml-list] Type visibility limitation in recursive modules
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I do not know if this is the intended behavior.  It may very well be.  
However, it appears we can easily work around this by simply abstracting the 
type later.  Eg.

module rec Aleph :
    sig
        type t = Tag of Beth.t
    end =
    struct
        type t = Tag of Beth.t
    end
and Beth :
    sig
        type t = Aleph.t list
        val scandalous : Aleph.t
    end =
    struct
        type t = Aleph.t list
        let scandalous = Aleph.Tag((* HERE BE DRAGONS *) [])
    end

module Beth = (Beth:sig type t val scandalous : Aleph.t end)


# Beth.scandalous;;
- - : Aleph.t = Aleph.Tag []
# Aleph.Tag [];;
- - : Aleph.t = Aleph.Tag []
# (Aleph.Tag []) = Beth.scandalous;;
- - : bool = true

Happy Holidays,

Peng



On Sunday 23 December 2007 09:24:55 am Márk S. Zoltán wrote:
> Behold the following code snippet:
>
> module rec Aleph :
>     sig
>         type t = Tag of Beth.t
>     end =
>     struct
>         type t = Tag of Beth.t
>     end
> and Beth :
>     sig
>         type t
>         val scandalous : Aleph.t
>     end =
>     struct
>         type t = Aleph.t list
>         let scandalous = Aleph.Tag((* HERE BE DRAGONS *) [])
>     end
>
> The compiler complains that the empty list after HERE BE DRAGONS has
> type 'a list but it is used with type Beth.t. I'd expect the compiler to
> discover that those types can be unified via 'a == Aleph.t, since as far
> as I can tell, all necessary facts are visible at that point. Replacing
> "Beth : sig type t ..." with "Beth : sig type t = Aleph.t list ..." does
> away with the error, but I would very much like to keep Beth.t an opaque
> type. Is this an intended behavior? And if it is intended, is there a
> way to tell the compiler what I really want it to do?
>
> Thanks in advance for any help.
>
>     Z-
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFHbpj4fIRcEFL/JewRAiRrAJ9lkWenFBHkG2IwRTuRDVN92JCRPQCgjjZV
INwvriBZ/NF25J3ApX8lKn8=
=UpHJ
-----END PGP SIGNATURE-----