Backticks are for Polymorphic Variants...

Documentation is in plain sight... and yet kind of hidden. :) Here's the Polymorphic Variants section of the manual: http://caml.inria.fr/pub/docs/manual-ocaml/lablexamples.html#sec46

And at the bottom of the "Advanced Use" subsection it introduces the abbreviated syntax for matching.

The Polymorphic Variant chapter of Real World OCaml might be useful too, though I couldn't see any reference to the abbreviated matching with #, even in the subtyping topic in the Objects chapter.

On Fri, Jun 10, 2016 at 1:05 PM, Hendrik Boom <hendrik@topoi.pooq.com> wrote:
On Fri, Jun 10, 2016 at 06:25:57PM +0000, dario.teixeira@yahoo.com wrote:
> Hi,
>
> > (b) Is there any way to do a run-time type-test on a value of a
> > specific statically known supertype to test whether it is actually a
> > value of a known specified subtype, and if so to proceed to use it as
> > that subtype?
>
> I reckon the "#" syntax may be what you are looking for.
> It works with polymorphic variants and objects (types
> where row-polymorphism applies).  Small example:
>
> type foo = [ `A | `B | `C ]
> type bar = [ `D | `E | `F ]
> type foobar = [ foo | bar ]
>
> let f = function
>   | #foo -> "Foo"
>   | #bar -> "Bar"

Haven't encountered the 3 syntax or the ` syntax.  Where is it
docuumented, so I can start to understand?

-- hendrik

>
> Hope this helps!
> Best regards,
>
> Dario Teixeira

--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs