Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] revised syntax for abstract types ?

1 view
Skip to first unread message

Serge Leblanc

unread,
Dec 10, 2009, 6:57:00 AM12/10/09
to caml...@yquem.inria.fr
Hi, the documentation for the revised syntax explain that abstract types
are expressed by :
type bar = 'a; but ocaml returns an error.


#
Objective Caml version 3.11.1

Camlp4 Parsing version 3.11.1

# type bar = 'a ;
Error: Unbound type parameter 'a

http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html

Thanks,
--
Serge Leblanc
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 0x33243C1B
Fingerprint = 066C 005F 5595 D85C 7673 D969 1DD4 90C4 3324 3C1B

signature.asc

Nicolas Pouillard

unread,
Dec 10, 2009, 8:49:54 AM12/10/09
to Serge Leblanc, caml-list
Excerpts from Serge Leblanc's message of Thu Dec 10 12:56:44 +0100 2009:

> Hi, the documentation for the revised syntax explain that abstract types
> are expressed by :

The documentation is too old, abstract types now have the same syntax in
revised than in the original OCaml syntax.

--
Nicolas Pouillard
http://nicolaspouillard.fr

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Stefano Zacchiroli

unread,
Dec 10, 2009, 9:29:35 AM12/10/09
to caml...@yquem.inria.fr
On Thu, Dec 10, 2009 at 02:49:43PM +0100, Nicolas Pouillard wrote:
> Excerpts from Serge Leblanc's message of Thu Dec 10 12:56:44 +0100 2009:
> > Hi, the documentation for the revised syntax explain that abstract types
> > are expressed by :
>
> The documentation is too old

Any chance that it will be updated any time soon?

--
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
Dietro un grande uomo c'� ..| . |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu � tous ceux que j'aime

Serge Leblanc

unread,
Dec 10, 2009, 1:10:46 PM12/10/09
to Nicolas Pouillard, caml-list
On Thu, 2009-12-10 at 14:49 +0100, Nicolas Pouillard wrote:

> Excerpts from Serge Leblanc's message of Thu Dec 10 12:56:44 +0100 2009:
> > Hi, the documentation for the revised syntax explain that abstract types
> > are expressed by :
>
> The documentation is too old, abstract types now have the same syntax in
> revised than in the original OCaml syntax.
>


In the following types definitions,

type trie 'a = [ Trie of arcs 'a ]
and arcs 'a = list ('a * trie 'a);

type zipper 'a = [ Top | Zip of (arcs 'a * 'a * arcs 'a * zipper 'a) ]
and edit_state 'a = (zipper 'a * trie 'a);

why is it not possible to describe them thus ?

type letter = 'a;
type trie = [ Trie of arcs ]
and arcs = list (letter * trie);

type zipper = [ Top | Zip of (arcs * letter * arcs * zipper) ]
and edit_state = (zipper * trie);

Thanks for your help.

signature.asc

Jacques Garrigue

unread,
Dec 10, 2009, 7:18:17 PM12/10/09
to serge....@orange.fr, caml...@yquem.inria.fr
From: Serge Leblanc <serge....@orange.fr>

> In the following types definitions,
>
> type trie 'a = [ Trie of arcs 'a ]
> and arcs 'a = list ('a * trie 'a);
>
> type zipper 'a = [ Top | Zip of (arcs 'a * 'a * arcs 'a * zipper 'a) ]
> and edit_state 'a = (zipper 'a * trie 'a);
>
> why is it not possible to describe them thus ?
>
> type letter = 'a;
> type trie = [ Trie of arcs ]
> and arcs = list (letter * trie);
>
> type zipper = [ Top | Zip of (arcs * letter * arcs * zipper) ]
> and edit_state = (zipper * trie);

Note first that revised syntax is just syntax, it does not change the
semantics. So, translating your question on a simpler example in
standard syntax, how does

type 'a list = Nil | Cons of 'a * 'a list

relate to

type elt
type list = Nil | Cons of elt * list

The answer is that they describe the same data, but in an incompatible
way. The first approach uses ML polymorphism, so that you can build a
list of any given type, letting the type checker choose the element
type.

The second is a signature, and should be used in combination with
functors, the type being chosen explicitly. For instance, you can
write a map function in the following way:

module type List = sig
type elt
type list = Nil | Cons of elt * list
end
module F(T:List) = struct
open T
let rec map f = function
Nil -> Nil
| Cons (h,t) -> Cons (f h, map f t)
end

module IntList = struct
type elt = int
type list = Nil | Cons of elt * list
end
module IntM = F(IntList);;

IntM.map succ (IntList.Cons (1, IntList.Nil));;

Again, these two definitions of list, while representing the same data,
are incompatible.

Hope this helps.

Jacques Garrigue

0 new messages