caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* revised syntax for abstract types ?
@ 2009-12-10 11:56 Serge Leblanc
  2009-12-10 13:49 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 5+ messages in thread
From: Serge Leblanc @ 2009-12-10 11:56 UTC (permalink / raw)
  To: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 505 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 1138 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] revised syntax for abstract types ?
  2009-12-10 11:56 revised syntax for abstract types ? Serge Leblanc
@ 2009-12-10 13:49 ` Nicolas Pouillard
  2009-12-10 14:29   ` Stefano Zacchiroli
  2009-12-10 18:10   ` Serge Leblanc
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2009-12-10 13:49 UTC (permalink / raw)
  To: Serge Leblanc; +Cc: 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] revised syntax for abstract types ?
  2009-12-10 13:49 ` [Caml-list] " Nicolas Pouillard
@ 2009-12-10 14:29   ` Stefano Zacchiroli
  2009-12-10 18:10   ` Serge Leblanc
  1 sibling, 0 replies; 5+ messages in thread
From: Stefano Zacchiroli @ 2009-12-10 14:29 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] revised syntax for abstract types ?
  2009-12-10 13:49 ` [Caml-list] " Nicolas Pouillard
  2009-12-10 14:29   ` Stefano Zacchiroli
@ 2009-12-10 18:10   ` Serge Leblanc
  2009-12-11  0:14     ` Jacques Garrigue
  1 sibling, 1 reply; 5+ messages in thread
From: Serge Leblanc @ 2009-12-10 18:10 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 1024 bytes --]

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.
--
Serge Leblanc
gpg --keyserver  hkp://keyserver.ubuntu.com:11371 --recv-keys 0x33243C1B
Fingerprint = 066C 005F 5595 D85C 7673  D969 1DD4 90C4 3324 3C1B

[-- Attachment #1.2: Type: text/html, Size: 2748 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] revised syntax for abstract types ?
  2009-12-10 18:10   ` Serge Leblanc
@ 2009-12-11  0:14     ` Jacques Garrigue
  0 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2009-12-11  0:14 UTC (permalink / raw)
  To: serge.leblanc; +Cc: nicolas.pouillard, caml-list

From: Serge Leblanc <serge.leblanc@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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-12-11  0:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-10 11:56 revised syntax for abstract types ? Serge Leblanc
2009-12-10 13:49 ` [Caml-list] " Nicolas Pouillard
2009-12-10 14:29   ` Stefano Zacchiroli
2009-12-10 18:10   ` Serge Leblanc
2009-12-11  0:14     ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).