Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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_(!).

Thanks..

--KW 8-)

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners