Re: "ocaml_beginners"::[] The type of all possible polymorphic variants

Expand Messages
• -[ Tue, Jun 07, 2011 at 10:01:15PM +0200, Philippe ]---- ... Thank you for the pointers. Incidentally this just emmerged out of a google search:
Message 1 of 11 , Jun 7, 2011
-[ Tue, Jun 07, 2011 at 10:01:15PM +0200, Philippe ]----
> Unfortunately not, and that is a pity because there are several clever
> uses of type constraints. The best documents I'm aware of are jacques
> garrigue posts on the caml list. Maybe you can also check his
> publications and slides on variants and objects. They are a must-see
> if you use polymorphic variants intensively. If you want I'll look
> more precise references.

Thank you for the pointers.
Incidentally this just emmerged out of a google search:

http://www.cs.cornell.edu/Courses/cs3110/2010sp/lectures/lec26a.htm

Very interresting on the "unification" thing.
• ... Could you explain this a bit more? what does: a constraint a mean? pt ... [Non-text portions of this message have been removed]
Message 2 of 11 , Jun 8, 2011
On Tue, Jun 7, 2011 at 6:18 AM, Philippe Veber <philippe.veber@...>wrote:

>
>
> Hi,
> I'm pretty sure you have to add a type variable if you want to keep it
> open,
> as in
>
> type 'a t = 'a constraint 'a = [> `A | `B];;
>

Could you explain this a bit more? what does: 'a constraint 'a
mean?

pt

>
> ph.
>
> 2011/6/7 <rixed@...>
>
>
> > When defining a polymorphic variant, say :
> >
> > type things = [ `This | `That ]
> >
> > one is not allowed to 'open' this type to other variants :
> >
> > # type things = [> `This | `That ];;
> > Error: A type variable is unbound in this type declaration.
> > In type [> `That | `This ] as 'a the variable 'a is unbound
> >
> >
> > Is there a way to define this ? My "understanding" of how
> > polymorphic variants are encoded suggest that it is possible,
> > but I can't write it.
> >
> > I need this type for a record field.
> >
> >
> >
> > ------------------------------------
>
> >
> > Archives up to December 31, 2010 are also downloadable at
> > http://www.connettivo.net/cntprojects/ocaml_beginners
> > The archives of the very official ocaml list (the seniors' one) can be
> > found at http://caml.inria.fr
> > Attachments are banned and you're asked to be polite, avoid flames
> >
> >
> >
> >
>
> [Non-text portions of this message have been removed]
>
>
>

[Non-text portions of this message have been removed]
• 2011/6/8 Phil Tomson ... You should read it more like this type a t = a constraint a = [ `A| `B] so here you say 2 things - a t is
Message 3 of 11 , Jun 8, 2011
2011/6/8 Phil Tomson <rubyfan@...>

> On Tue, Jun 7, 2011 at 6:18 AM, Philippe Veber <philippe.veber@...
> >wrote:
>
> >
> >
> > Hi,
> > I'm pretty sure you have to add a type variable if you want to keep it
> > open,
> > as in
> >
> > type 'a t = 'a constraint 'a = [> `A | `B];;
> >
>
> Could you explain this a bit more? what does: 'a constraint 'a
> mean?
>
> pt
>
You should read it more like this

type 'a t = 'a
constraint 'a = [> `A| `B]

so here you say 2 things
- 'a t is defined as the type 'a
- 'a should be a type that can be unified with [> `A | `B], that is a
polymorphic variant type that contains at least `A and `B constructors.

you could write several constraints in your type definition :

type 'a t = 'a
constraint 'a = [> `A]
constraint 'a = [> `B]

which is equivalent to the former.

hth,
ph.

>
> >
> > ph.
> >
> > 2011/6/7 <rixed@...>
> >
> >
> > > When defining a polymorphic variant, say :
> > >
> > > type things = [ `This | `That ]
> > >
> > > one is not allowed to 'open' this type to other variants :
> > >
> > > # type things = [> `This | `That ];;
> > > Error: A type variable is unbound in this type declaration.
> > > In type [> `That | `This ] as 'a the variable 'a is unbound
> > >
> > >
> > > Is there a way to define this ? My "understanding" of how
> > > polymorphic variants are encoded suggest that it is possible,
> > > but I can't write it.
> > >
> > > I need this type for a record field.
> > >
> > >
> > >
> > > ------------------------------------
> >
> > >
> > > Archives up to December 31, 2010 are also downloadable at
> > > http://www.connettivo.net/cntprojects/ocaml_beginners
> > > The archives of the very official ocaml list (the seniors' one) can be
> > > found at http://caml.inria.fr
> > > Attachments are banned and you're asked to be polite, avoid flames
> > > etc.Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> http://www.connettivo.net/cntprojects/ocaml_beginners
> The archives of the very official ocaml list (the seniors' one) can be
> found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames
>
>
>
>

[Non-text portions of this message have been removed]
• On Tue, 7 Jun 2011 15:18:33 +0200 ... Shorter syntax : # type a things = [ `This | `That ] as a;; type a things = a constraint a = [ `That | `This ] --
Message 4 of 11 , Jun 8, 2011
On Tue, 7 Jun 2011 15:18:33 +0200
Philippe Veber <philippe.veber@...> wrote:

> I'm pretty sure you have to add a type variable if you want to keep it open,
> as in
>
> type 'a t = 'a constraint 'a = [> `A | `B];;

Shorter syntax :

# type 'a things = [> `This | `That ] as 'a;;
type 'a things = 'a constraint 'a = [> `That | `This ]

--
ygrek
http://ygrek.org.ua
• The references you mention would be of interest to me. It will be great if you can provide them. Thanks. ... [Non-text portions of this message have been
Message 5 of 11 , Jun 12, 2011
The references you mention would be of interest to me. It will be great if
you can provide them. Thanks.

On Tue, Jun 7, 2011 at 4:01 PM, Philippe <philippe.veber@...> wrote:

>
>
> Unfortunately not, and that is a pity because there are several clever
> uses of type constraints. The best documents I'm aware of are jacques
> garrigue posts on the caml list. Maybe you can also check his
> publications and slides on variants and objects. They are a must-see
> if you use polymorphic variants intensively. If you want I'll look
> more precise references.
>
> Ph.
>
> Le 7 juin 2011 � 17:11, rixed@... a �crit :
>
>
> >> type 'a t = 'a constraint 'a = [> `A | `B];;
> >
> > Never seen this before.
> > Seams to work, thank you!
> >
> > Do you know of any tutorial that could explain in greater length these
> > few lines of documentation:
> >
> > The construct constraint ' ident = typexpr allows to specify type
> > parameters. Any actual type argument corresponding to the type
> > parameter
> > ident has to be an instance of typexpr (more precisely, ident and
> > typexpr are unified). Type variables of typexpr can appear in the type
> > equation and the type declaration.
> >
> >
> >
> > ------------------------------------
>
> >
> > Archives up to December 31, 2010 are also downloadable at
> http://www.connettivo.net/cntprojects/ocaml_beginners
> > The archives of the very official ocaml list (the seniors' one) can
> > be found at http://caml.inria.fr
> > Attachments are banned and you're asked to be polite, avoid flames
> >
> >
> >
>
>
>

[Non-text portions of this message have been removed]
• Hi Ashish, You can check this page : http://www.math.nagoya-u.ac.jp/~garrigue/papers/ and notably: - *Private rows: abstracting the unnamed - **Code reuse
Message 6 of 11 , Jun 14, 2011
Hi Ashish,

and notably:
- *Private rows: abstracting the unnamed
- **Code reuse through polymorphic variants*.
- *Unions de variants polymorphes abstraits (unfortunately in french, but
check the slides which might of special interest to you)*

2011/6/13 Ashish Agarwal <agarwal1975@...>

> The references you mention would be of interest to me. It will be great if
> you can provide them. Thanks.
>
> On Tue, Jun 7, 2011 at 4:01 PM, Philippe <philippe.veber@...> wrote:
>
> >
> >
> > Unfortunately not, and that is a pity because there are several clever
> > uses of type constraints. The best documents I'm aware of are jacques
> > garrigue posts on the caml list. Maybe you can also check his
> > publications and slides on variants and objects. They are a must-see
> > if you use polymorphic variants intensively. If you want I'll look
> > more precise references.
> >
> > Ph.
> >
> > Le 7 juin 2011 ą 17:11, rixed@... a écrit :
> >
> >
> > >> type 'a t = 'a constraint 'a = [> `A | `B];;
> > >
> > > Never seen this before.
> > > Seams to work, thank you!
> > >
> > > Do you know of any tutorial that could explain in greater length these
> > > few lines of documentation:
> > >
> > > The construct constraint ' ident = typexpr allows to specify type
> > > parameters. Any actual type argument corresponding to the type
> > > parameter
> > > ident has to be an instance of typexpr (more precisely, ident and
> > > typexpr are unified). Type variables of typexpr can appear in the type
> > > equation and the type declaration.
> > >
> > >
> > >
> > > ------------------------------------
> >
> > >
> > > Archives up to December 31, 2010 are also downloadable at
> > http://www.connettivo.net/cntprojects/ocaml_beginners
> > > The archives of the very official ocaml list (the seniors' one) can
> > > be found at http://caml.inria.fr
> > > Attachments are banned and you're asked to be polite, avoid flames
> > > etc.Yahoo! Groups Links
> > >
> > >
> > >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> http://www.connettivo.net/cntprojects/ocaml_beginners
> The archives of the very official ocaml list (the seniors' one) can be
> found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames
>
>
>
>

[Non-text portions of this message have been removed]
Your message has been successfully submitted and would be delivered to recipients shortly.