Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Documentation error - #myvariant
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-29 (13:54)
From: Keith Wansbrough <Keith.Wansbrough@c...>
Subject: Re: [Caml-list] Documentation error - #myvariant
Rémi Vanicat writes:
> The documentation is accurate.

I think the documentation is unclear, and should be clarified.  All
the OCaml manual says is:

  "if you have defined type myvariant = [`Tag1 int | `Tag2 bool], then
  the pattern #myvariant is equivalent to writing (`Tag1(_ : int) |
  `Tag2(_ : bool))."

This says nothing about how recursive types are treated when
#myvariant occurs in a supertype context.  Since this is surely a
common use of polymorphic variants, it should at least say "the g1 / g
example is misleading, as this #myvariant style won't work in most
useful cases".

> In fact, your code will do what you want if you don't define your type
> as recursive but as polymorphic :

OK - that type trick corresponds to the term trick already explained
in the manual, with passing the recursive function explicitly.  Shades
of Steele, 1994, _Building Interpreters by Composing Monads_(!).


--KW 8-)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: