* [Caml-list] First Class modules -A bug in 4.00?
@ 2012-06-08 2:35 Hongbo Zhang
2012-06-08 3:22 ` Jacques Garrigue
0 siblings, 1 reply; 6+ messages in thread
From: Hongbo Zhang @ 2012-06-08 2:35 UTC (permalink / raw)
To: Caml List
Hi, List
I am not sure this is a bug or not?
Below is a contrived example:
------------------
module type S = sig
type t=int
module X : sig type u end
end
let f ( module X : S) (y:X.X.u) =
3
--------------------
Error: This pattern matches values of type X.X.u
but a pattern was expected which matches values of type X.X.u
The type constructor X.X.u would escape its scope
-- Thanks
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] First Class modules -A bug in 4.00?
2012-06-08 2:35 [Caml-list] First Class modules -A bug in 4.00? Hongbo Zhang
@ 2012-06-08 3:22 ` Jacques Garrigue
2012-06-08 15:25 ` bob zhang
2012-06-08 20:25 ` Milan Stanojević
0 siblings, 2 replies; 6+ messages in thread
From: Jacques Garrigue @ 2012-06-08 3:22 UTC (permalink / raw)
To: Hongbo Zhang; +Cc: caml-list
On 2012/06/08, at 11:35, Hongbo Zhang wrote:
> Hi, List
> I am not sure this is a bug or not?
>
> Below is a contrived example:
> ------------------
> module type S = sig
> type t=int
> module X : sig type u end
> end
>
> let f ( module X : S) (y:X.X.u) =
> 3
> --------------------
> Error: This pattern matches values of type X.X.u
> but a pattern was expected which matches values of type X.X.u
> The type constructor X.X.u would escape its scope
> -- Thanks
Definitely, this is not a bug.
Type X.X.u is abstract, and showing it outside (as by taking an argument
of that type) would be meaningless.
What you might have meant is:
let f (type a) (module X : S with type X.u = a) (y : X.X.u) = 3
This is typable (but I'm not sure it means anything...)
Jacques Garrigue
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] First Class modules -A bug in 4.00?
2012-06-08 3:22 ` Jacques Garrigue
@ 2012-06-08 15:25 ` bob zhang
2012-06-08 15:29 ` bob zhang
2012-06-08 20:25 ` Milan Stanojević
1 sibling, 1 reply; 6+ messages in thread
From: bob zhang @ 2012-06-08 15:25 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 1478 bytes --]
Thanks. it helps.
Here's what I really want, is there any way to walk around if not possible?
S1 is not written by me.
--------------------------------------------------------------------
module type S1 = sig
module Inner : sig
type 'a t
val add : 'a t -> 'a t -> int
end
end
let f1
(type s)
(type a)
(module Y : S1 with type s Inner.t = a) (y: s Y.Inner.t) =
Y.Inner.add y y
------------------------------------------------------------------------------------------------------------
On Thu, Jun 7, 2012 at 11:22 PM, Jacques Garrigue <
garrigue@math.nagoya-u.ac.jp> wrote:
> On 2012/06/08, at 11:35, Hongbo Zhang wrote:
>
> > Hi, List
> > I am not sure this is a bug or not?
> >
> > Below is a contrived example:
> > ------------------
> > module type S = sig
> > type t=int
> > module X : sig type u end
> > end
> >
> > let f ( module X : S) (y:X.X.u) =
> > 3
> > --------------------
> > Error: This pattern matches values of type X.X.u
> > but a pattern was expected which matches values of type X.X.u
> > The type constructor X.X.u would escape its scope
> > -- Thanks
>
> Definitely, this is not a bug.
> Type X.X.u is abstract, and showing it outside (as by taking an argument
> of that type) would be meaningless.
>
> What you might have meant is:
>
> let f (type a) (module X : S with type X.u = a) (y : X.X.u) = 3
>
> This is typable (but I'm not sure it means anything...)
>
> Jacques Garrigue
>
--
-- Bob
[-- Attachment #2: Type: text/html, Size: 2254 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] First Class modules -A bug in 4.00?
2012-06-08 15:25 ` bob zhang
@ 2012-06-08 15:29 ` bob zhang
0 siblings, 0 replies; 6+ messages in thread
From: bob zhang @ 2012-06-08 15:29 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]
Hi, List,
This works around the syntax error problem, but still does not work
------------------------------------------------------
module type S1 = sig
module Inner : sig
type 'a t
val add : 'a t -> 'a t -> int
end
type int_u = int Inner.t
end
let f1
(type s)
(type a)
(module Y : S1 with type int_u = a) (y: Y.int_u) =
Y.Inner.add y y
Jun 8, 2012 at 11:25 AM, bob zhang <bobzhang1988@gmail.com> wrote:
> Thanks. it helps.
> Here's what I really want, is there any way to walk around if not possible?
>
> S1 is not written by me.
> --------------------------------------------------------------------
> module type S1 = sig
> module Inner : sig
> type 'a t
> val add : 'a t -> 'a t -> int
> end
> end
>
> let f1
> (type s)
> (type a)
> (module Y : S1 with type s Inner.t = a) (y: s Y.Inner.t) =
> Y.Inner.add y y
>
> ------------------------------------------------------------------------------------------------------------
> On Thu, Jun 7, 2012 at 11:22 PM, Jacques Garrigue <
> garrigue@math.nagoya-u.ac.jp> wrote:
>
>> On 2012/06/08, at 11:35, Hongbo Zhang wrote:
>>
>> > Hi, List
>> > I am not sure this is a bug or not?
>> >
>> > Below is a contrived example:
>> > ------------------
>> > module type S = sig
>> > type t=int
>> > module X : sig type u end
>> > end
>> >
>> > let f ( module X : S) (y:X.X.u) =
>> > 3
>> > --------------------
>> > Error: This pattern matches values of type X.X.u
>> > but a pattern was expected which matches values of type X.X.u
>> > The type constructor X.X.u would escape its scope
>> > -- Thanks
>>
>> Definitely, this is not a bug.
>> Type X.X.u is abstract, and showing it outside (as by taking an argument
>> of that type) would be meaningless.
>>
>> What you might have meant is:
>>
>> let f (type a) (module X : S with type X.u = a) (y : X.X.u) = 3
>>
>> This is typable (but I'm not sure it means anything...)
>>
>> Jacques Garrigue
>>
>
>
>
> --
> -- Bob
>
--
-- Bob
[-- Attachment #2: Type: text/html, Size: 3268 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] First Class modules -A bug in 4.00?
2012-06-08 3:22 ` Jacques Garrigue
2012-06-08 15:25 ` bob zhang
@ 2012-06-08 20:25 ` Milan Stanojević
2012-06-10 9:27 ` Jacques Garrigue
1 sibling, 1 reply; 6+ messages in thread
From: Milan Stanojević @ 2012-06-08 20:25 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: Hongbo Zhang, caml-list
On Thu, Jun 7, 2012 at 11:22 PM, Jacques Garrigue
<garrigue@math.nagoya-u.ac.jp> wrote:
> On 2012/06/08, at 11:35, Hongbo Zhang wrote:
>
>> Hi, List
>> I am not sure this is a bug or not?
>>
>> Below is a contrived example:
>> ------------------
>> module type S = sig
>> type t=int
>> module X : sig type u end
>> end
>>
>> let f ( module X : S) (y:X.X.u) =
>> 3
>> --------------------
>> Error: This pattern matches values of type X.X.u
>> but a pattern was expected which matches values of type X.X.u
>> The type constructor X.X.u would escape its scope
>> -- Thanks
>
> Definitely, this is not a bug.
> Type X.X.u is abstract, and showing it outside (as by taking an argument
> of that type) would be meaningless.
What do you mean by "abstract type" here?
For example, I'd call X.t in the following example abstract and it is
perfectly fine to use it as argument.
module X : sig type t end = struct type t = int end
let f (x : X.t) = 3
But I guess you mean something else by abstract? Is my terminology
completely wrong?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] First Class modules -A bug in 4.00?
2012-06-08 20:25 ` Milan Stanojević
@ 2012-06-10 9:27 ` Jacques Garrigue
0 siblings, 0 replies; 6+ messages in thread
From: Jacques Garrigue @ 2012-06-10 9:27 UTC (permalink / raw)
To: Milan Stanojević; +Cc: caml-list
On 2012/06/09, at 5:25, Milan Stanojević wrote:
> On Thu, Jun 7, 2012 at 11:22 PM, Jacques Garrigue
> <garrigue@math.nagoya-u.ac.jp> wrote:
>> On 2012/06/08, at 11:35, Hongbo Zhang wrote:
>>
>>> Hi, List
>>> I am not sure this is a bug or not?
>>>
>>> Below is a contrived example:
>>> ------------------
>>> module type S = sig
>>> type t=int
>>> module X : sig type u end
>>> end
>>>
>>> let f ( module X : S) (y:X.X.u) =
>>> 3
>>> --------------------
>>> Error: This pattern matches values of type X.X.u
>>> but a pattern was expected which matches values of type X.X.u
>>> The type constructor X.X.u would escape its scope
>>> -- Thanks
>>
>> Definitely, this is not a bug.
>> Type X.X.u is abstract, and showing it outside (as by taking an argument
>> of that type) would be meaningless.
>
> What do you mean by "abstract type" here?
The problem here is that X.X.u is both abstract, and introduced by the
pattern (module X : S), and as such is only valid in the scope of X.
> For example, I'd call X.t in the following example abstract and it is
> perfectly fine to use it as argument.
> module X : sig type t end = struct type t = int end
> let f (x : X.t) = 3
You can actually get the same error by using a reference:
let r = ref [];;
module X : sig type t end = struct type t = int end
let f (x : X.t) = 3 ;;
r := [f];;
Error: This expression has type X.t -> int
but an expression was expected of type X.t -> int
The type constructor X.t would escape its scope
In case of a usual module definition, references defined before it
are out of scope.
Jacques Garrigue
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-10 9:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-08 2:35 [Caml-list] First Class modules -A bug in 4.00? Hongbo Zhang
2012-06-08 3:22 ` Jacques Garrigue
2012-06-08 15:25 ` bob zhang
2012-06-08 15:29 ` bob zhang
2012-06-08 20:25 ` Milan Stanojević
2012-06-10 9:27 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox