caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* polymorphic variants, long form
@ 2009-01-20 17:37 Jacques Carette
  2009-01-20 17:39 ` [Caml-list] " Luc Maranget
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Carette @ 2009-01-20 17:37 UTC (permalink / raw)
  To: caml-list

What is the proper 'long name' of a polymorphic variant?
module S = struct type a = [`Foo of int] end

How do I refer to `Foo without opening S?  Both S.`Foo and `S.Foo are 
syntax errors.

Jacques


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

* Re: [Caml-list] polymorphic variants, long form
  2009-01-20 17:37 polymorphic variants, long form Jacques Carette
@ 2009-01-20 17:39 ` Luc Maranget
  2009-01-20 18:04   ` Jacques Carette
  0 siblings, 1 reply; 4+ messages in thread
From: Luc Maranget @ 2009-01-20 17:39 UTC (permalink / raw)
  To: Jacques Carette; +Cc: caml-list

> What is the proper 'long name' of a polymorphic variant?
> module S = struct type a = [`Foo of int] end
> 
> How do I refer to `Foo without opening S?  Both S.`Foo and `S.Foo are 
> syntax errors.
> 
> Jacques

'Foo does the job, it does not refer to any previous type definition.

% ocaml
        Objective Caml version 3.11.0

# `Foo;;
- : [> `Foo ] = `Foo

-- Luc


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

* Re: [Caml-list] polymorphic variants, long form
  2009-01-20 17:39 ` [Caml-list] " Luc Maranget
@ 2009-01-20 18:04   ` Jacques Carette
  2009-01-21  9:39     ` Romain Bardou
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Carette @ 2009-01-20 18:04 UTC (permalink / raw)
  To: Luc Maranget; +Cc: caml-list

Luc Maranget wrote:
>> What is the proper 'long name' of a polymorphic variant?
>> module S = struct type a = [`Foo of int] end
>>
>> How do I refer to `Foo without opening S?  Both S.`Foo and `S.Foo are 
>> syntax errors.
>>
>> Jacques
>>     
>
> 'Foo does the job, it does not refer to any previous type definition.
>
> % ocaml
>         Objective Caml version 3.11.0
>
> # `Foo;;
> - : [> `Foo ] = `Foo
>   
Just  a few minutes after I sent my email, I remembered the answer 
myself: unlike normal variants, polymorphic variants are not scoped but 
affect the namespace in a GLOBAL way.  Both extremely convenient and 
non-modular at the same time.

Jacques


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

* Re: [Caml-list] polymorphic variants, long form
  2009-01-20 18:04   ` Jacques Carette
@ 2009-01-21  9:39     ` Romain Bardou
  0 siblings, 0 replies; 4+ messages in thread
From: Romain Bardou @ 2009-01-21  9:39 UTC (permalink / raw)
  To: Jacques Carette; +Cc: Luc Maranget, caml-list

Jacques Carette a écrit :
> Luc Maranget wrote:
>>> What is the proper 'long name' of a polymorphic variant?
>>> module S = struct type a = [`Foo of int] end
>>>
>>> How do I refer to `Foo without opening S?  Both S.`Foo and `S.Foo are 
>>> syntax errors.
>>>
>>> Jacques
>>>     
>>
>> 'Foo does the job, it does not refer to any previous type definition.
>>
>> % ocaml
>>         Objective Caml version 3.11.0
>>
>> # `Foo;;
>> - : [> `Foo ] = `Foo
>>   
> Just  a few minutes after I sent my email, I remembered the answer 
> myself: unlike normal variants, polymorphic variants are not scoped but 
> affect the namespace in a GLOBAL way.  Both extremely convenient and 
> non-modular at the same time.

It does not actually affect the namespace, as there is no namespace for 
polymorphic variants. All variant names can be used, anywhere, and then 
types are inferred. Your type definition S.a does not declares anything 
but S.a, which is just a type abbreviation and could be expanded to 
[`Foo of int] everywhere.

-- 
Romain Bardou


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

end of thread, other threads:[~2009-01-21  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-20 17:37 polymorphic variants, long form Jacques Carette
2009-01-20 17:39 ` [Caml-list] " Luc Maranget
2009-01-20 18:04   ` Jacques Carette
2009-01-21  9:39     ` Romain Bardou

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