# types and polymorphic variants

From: Manuel Fahndrich (maf@microsoft.com)
Date: Thu Feb 24 2000 - 21:51:11 MET

  • Next message: Gerd Stolpmann: "Re: Portability of applications written in OCAML: C stuff"

    What is the meaning of #foo, when foo is a polymorphic variant set?

    type foo = [`A | `B | `C]

    I assumed that it was the following:

            #foo = [<`A | `B | `C ]

    that is a set containing at most `A | `B | `C. In other words a subtype of

    But consider the following example.

    type foo = [`A | `B | `C]

    let foo1 (x : #foo as 'a) = x

    let y1 = foo1 (`A : [`A])

    let foo2 (x : [< `A | `B | `C] as 'a) = x

    let y2 = foo2 (`A : [`A])

    The complier tells me:

    ocamlc -c -i ex1.ml

    type foo = [`A|`B|`C]
    val foo1 : (#foo as 'a) -> 'a
    val y1 : foo
    val foo2 : ([<`A|`B|`C] as 'a) -> 'a
    val y2 : [`A]

    The first function returns me only a foo, the second function returns me
    [`A] as expected. Thus my question, what exactly does #foo stand for. I do
    understand row variables, but the issue with the lower and upper bounds > <
    in variant types seems new. Is there a paper describing these?

    I seem to write types of the form [< `A | `B | `C] a lot. Shouldn't there be
    an abbreviation for those as well? Maybe #<foo?

    Thanks in advance for such a wonderfully expressive type system!


    This archive was generated by hypermail 2b29 : Fri Feb 25 2000 - 14:05:30 MET