Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* type abbreviation for open polymorhic variants?
@ 2005-08-18 21:03 Norman Ramsey
  2005-08-18 21:45 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Norman Ramsey @ 2005-08-18 21:03 UTC (permalink / raw)
  To: caml-list

I wish to define an abbreviation for the following type:

         [> `Nil
    	 | `Number   of float
    	 | `String   of string
    	 | `Function of func
     	 | `Table    of table
         ]

I am assuming that the underlying machinery involves something like
row polymorphism, but I don't know how to name the 'row variable'.
I tried

  type 'a t = ['a 
              | `Nil
              | `Number   of float
              | `String   of string
              | `Function of func
              | `Table    of table
              ]

but this suggestion was roundly rejected by the compiler.

Does anybody know how to do this?  I couldn't find anything in the
syntax for polymorphic-variant type expressions.


Norman



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

* Re: [Caml-list] type abbreviation for open polymorhic variants?
  2005-08-18 21:03 type abbreviation for open polymorhic variants? Norman Ramsey
@ 2005-08-18 21:45 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2005-08-18 21:45 UTC (permalink / raw)
  To: nr; +Cc: caml-list

From: nr@eecs.harvard.edu (Norman Ramsey)

> I wish to define an abbreviation for the following type:
> 
>          [> `Nil
>     	 | `Number   of float
>     	 | `String   of string
>     	 | `Function of func
>      	 | `Table    of table
>          ]
> 
> I am assuming that the underlying machinery involves something like
> row polymorphism, but I don't know how to name the 'row variable'.

You can write
type 'a t = 'a constraint 'a =
     [> `Nil
     | `Number   of float
     | `String   of string
     | `Function of func
     | `Table    of table ]

But it seems simpler to write

type t =
     [ `Nil
     | `Number   of float
     | `String   of string
     | `Function of func
     | `Table    of table ]

and use it as [< t] where needed.

Jacques Garrigue


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

end of thread, other threads:[~2005-08-18 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-18 21:03 type abbreviation for open polymorhic variants? Norman Ramsey
2005-08-18 21:45 ` [Caml-list] " Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox