* Why is this allowed?
@ 2010-05-31 14:46 Jacques Carette
2010-05-31 15:06 ` [Caml-list] " Lukasz Stafiniak
2010-05-31 15:43 ` Till Varoquaux
0 siblings, 2 replies; 8+ messages in thread
From: Jacques Carette @ 2010-05-31 14:46 UTC (permalink / raw)
To: caml-list
type foo = Foo
let x = Foo
type foo2 = Foo | Bar
let y = Foo
let z = (x,y) ;;
I thought that re-using of algebraic labels was not allowed - but
apparently it is? Note that this means that it is impossible to "text"
print such structures and hope to recover them uniquely. This also
causes very subtle issues when Marshal'ing, and grave issues for code
generation [think metaocaml].
Jacques
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-05-31 14:46 Why is this allowed? Jacques Carette
@ 2010-05-31 15:06 ` Lukasz Stafiniak
2010-05-31 15:48 ` Jacques Carette
2010-05-31 15:43 ` Till Varoquaux
1 sibling, 1 reply; 8+ messages in thread
From: Lukasz Stafiniak @ 2010-05-31 15:06 UTC (permalink / raw)
To: Jacques Carette; +Cc: caml-list
But what when someone includes or opens a module with Foo after "type
foo = Foo"? What when someone opens it locally in an expression?
Does a variant value have a unique type with a unique path so that it
would be possible to guarantee that within this unique path there are
no type *definitions* that override a variant name?
On Mon, May 31, 2010 at 4:46 PM, Jacques Carette <carette@mcmaster.ca> wrote:
> type foo = Foo
> let x = Foo
>
> type foo2 = Foo | Bar
> let y = Foo
> let z = (x,y) ;;
>
> I thought that re-using of algebraic labels was not allowed - but apparently
> it is?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-05-31 14:46 Why is this allowed? Jacques Carette
2010-05-31 15:06 ` [Caml-list] " Lukasz Stafiniak
@ 2010-05-31 15:43 ` Till Varoquaux
2010-05-31 15:54 ` Jacques Carette
1 sibling, 1 reply; 8+ messages in thread
From: Till Varoquaux @ 2010-05-31 15:43 UTC (permalink / raw)
To: Jacques Carette; +Cc: caml-list
AFAIK you are allowed to shadow just about anything in
implementations. If you wanted to keep the exact same interface but
retain the ability to avvoid the shadowing issue on the labels you
could do:
module Foo = struct
type t = Foo
end
type foo = Foo.t = Foo
module Foo2 = struct
type t = Foo | Bar
end
type foo2 = Foo2.t = Foo | Bar
HTH,
Till
On Mon, May 31, 2010 at 10:46 AM, Jacques Carette <carette@mcmaster.ca> wrote:
> type foo = Foo
> let x = Foo
>
> type foo2 = Foo | Bar
> let y = Foo
> let z = (x,y) ;;
>
> I thought that re-using of algebraic labels was not allowed - but apparently
> it is? Note that this means that it is impossible to "text" print such
> structures and hope to recover them uniquely. This also causes very subtle
> issues when Marshal'ing, and grave issues for code generation [think
> metaocaml].
>
> Jacques
>
> _______________________________________________
> 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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-05-31 15:06 ` [Caml-list] " Lukasz Stafiniak
@ 2010-05-31 15:48 ` Jacques Carette
0 siblings, 0 replies; 8+ messages in thread
From: Jacques Carette @ 2010-05-31 15:48 UTC (permalink / raw)
To: Lukasz Stafiniak; +Cc: caml-list
Lukasz Stafiniak wrote:
> But what when someone includes or opens a module with Foo after "type
> foo = Foo"? What when someone opens it locally in an expression?
>
I would be fine if type-level shadowing was disallowed for all those cases.
> Does a variant value have a unique type with a unique path so that it
> would be possible to guarantee that within this unique path there are
> no type *definitions* that override a variant name?
>
That would be nice.
Jacques
> On Mon, May 31, 2010 at 4:46 PM, Jacques Carette <carette@mcmaster.ca> wrote:
>
>> type foo = Foo
>> let x = Foo
>>
>> type foo2 = Foo | Bar
>> let y = Foo
>> let z = (x,y) ;;
>>
>> I thought that re-using of algebraic labels was not allowed - but apparently
>> it is?
>>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-05-31 15:43 ` Till Varoquaux
@ 2010-05-31 15:54 ` Jacques Carette
2010-06-09 15:11 ` Goswin von Brederlow
0 siblings, 1 reply; 8+ messages in thread
From: Jacques Carette @ 2010-05-31 15:54 UTC (permalink / raw)
To: Till Varoquaux; +Cc: caml-list
Nice trick - but my 'problem' [1] regards arbitrary valid OCaml code and
how to serialize code values. The issue seems to be that one needs to
attach an arbitrarily large typing environment to each part of a value,
as there is no global typing environment which will do the job (because
of shadowing).
Jacques
[1] Actually 'our' problem, in that this arose from some issues in
metaocaml, and I am working with Oleg to figure out what is going on.
Interestingly, this never arose in 3.09 and before.
Till Varoquaux wrote:
> AFAIK you are allowed to shadow just about anything in
> implementations. If you wanted to keep the exact same interface but
> retain the ability to avvoid the shadowing issue on the labels you
> could do:
>
> module Foo = struct
> type t = Foo
> end
> type foo = Foo.t = Foo
>
> module Foo2 = struct
> type t = Foo | Bar
> end
>
> type foo2 = Foo2.t = Foo | Bar
>
> HTH,
> Till
>
> On Mon, May 31, 2010 at 10:46 AM, Jacques Carette <carette@mcmaster.ca> wrote:
>
>> type foo = Foo
>> let x = Foo
>>
>> type foo2 = Foo | Bar
>> let y = Foo
>> let z = (x,y) ;;
>>
>> I thought that re-using of algebraic labels was not allowed - but apparently
>> it is? Note that this means that it is impossible to "text" print such
>> structures and hope to recover them uniquely. This also causes very subtle
>> issues when Marshal'ing, and grave issues for code generation [think
>> metaocaml].
>>
>> Jacques
>>
>> _______________________________________________
>> 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
>>
>>
>
> _______________________________________________
> 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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-05-31 15:54 ` Jacques Carette
@ 2010-06-09 15:11 ` Goswin von Brederlow
2010-06-09 15:17 ` bluestorm
0 siblings, 1 reply; 8+ messages in thread
From: Goswin von Brederlow @ 2010-06-09 15:11 UTC (permalink / raw)
To: Jacques Carette; +Cc: Till Varoquaux, caml-list
Jacques Carette <carette@mcmaster.ca> writes:
> Nice trick - but my 'problem' [1] regards arbitrary valid OCaml code
> and how to serialize code values. The issue seems to be that one
> needs to attach an arbitrarily large typing environment to each part
> of a value, as there is no global typing environment which will do the
> job (because of shadowing).
>
> Jacques
This is no different from
let x = 1
let x = 2
Shadowing is totally allowed in ocaml.
MfG
Goswin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-06-09 15:11 ` Goswin von Brederlow
@ 2010-06-09 15:17 ` bluestorm
2010-06-09 15:31 ` Jacques Carette
0 siblings, 1 reply; 8+ messages in thread
From: bluestorm @ 2010-06-09 15:17 UTC (permalink / raw)
To: Goswin von Brederlow; +Cc: Jacques Carette, Till Varoquaux, caml-list
[-- Attachment #1: Type: text/plain, Size: 237 bytes --]
It is actually not the case that type structure items can be shadowed :
# module A = struct type t = int;; type t = int end;;
Error: Multiple definition of the type name t.
Names must be unique in a given structure or signature.
[-- Attachment #2: Type: text/html, Size: 312 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Why is this allowed?
2010-06-09 15:17 ` bluestorm
@ 2010-06-09 15:31 ` Jacques Carette
0 siblings, 0 replies; 8+ messages in thread
From: Jacques Carette @ 2010-06-09 15:31 UTC (permalink / raw)
To: bluestorm; +Cc: Goswin von Brederlow, Till Varoquaux, caml-list
bluestorm wrote:
> It is actually not the case that type structure items can be shadowed :
>
> # module A = struct type t = int;; type t = int end;;
> Error: Multiple definition of the type name t.
> Names must be unique in a given structure or signature.
>
Exactly. My desired would be for this non-shadowing restriction to be
extended to all types, not just type structure items.
Shadowing at the value level is an entirely different issue, and is
perfectly fine as it is.
Jacques
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-06-09 15:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-31 14:46 Why is this allowed? Jacques Carette
2010-05-31 15:06 ` [Caml-list] " Lukasz Stafiniak
2010-05-31 15:48 ` Jacques Carette
2010-05-31 15:43 ` Till Varoquaux
2010-05-31 15:54 ` Jacques Carette
2010-06-09 15:11 ` Goswin von Brederlow
2010-06-09 15:17 ` bluestorm
2010-06-09 15:31 ` Jacques Carette
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox