* Upgrading sexplib-2.7.0 to camlp4 3.10
@ 2007-04-30 13:55 Joel Reymont
2007-04-30 14:01 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 13:55 UTC (permalink / raw)
To: Caml List; +Cc: Nicolas Pouillard
The bit below gives an error
| <:ctyp< $tp1$ . $tp2$ >> ->
ocamlc -c -I +camlp4 -pp camlp4orf -for-pack Sexplib pa_sexp_conv.ml
File "pa_sexp_conv.ml", line 105, characters 24-29:
While expanding quotation "ctyp" in a position of "patt":
Parse error: ident_of_ctyp: this type is not an identifier
How do I interpret this and what do I need to learn to fix it?
I'm still reading through Martin's pa_json translation but I don't
think he uses the construct above.
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 13:55 Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
@ 2007-04-30 14:01 ` Nicolas Pouillard
2007-04-30 14:07 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-04-30 14:01 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
> The bit below gives an error
>
> | <:ctyp< $tp1$ . $tp2$ >> ->
>
> ocamlc -c -I +camlp4 -pp camlp4orf -for-pack Sexplib pa_sexp_conv.ml
> File "pa_sexp_conv.ml", line 105, characters 24-29:
> While expanding quotation "ctyp" in a position of "patt":
> Parse error: ident_of_ctyp: this type is not an identifier
>
> How do I interpret this and what do I need to learn to fix it?
This is because dot cannot be used anywhere in types but just for identifiers.
So Foo.t is a type but not (int -> int).int even syntactically.
So you have to take the case <:ctyp< $id:i$ >> and then play with `i'
that is an ident and can be matched with <:ident< ... >>
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 14:01 ` Nicolas Pouillard
@ 2007-04-30 14:07 ` Joel Reymont
2007-04-30 14:17 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 14:07 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On Apr 30, 2007, at 3:01 PM, Nicolas Pouillard wrote:
> So you have to take the case <:ctyp< $id:i$ >> and then play with `i'
> that is an ident and can be matched with <:ident< ... >>
It looks like this is being taken care of by the first pattern.
It also looks like the second pattern is matching a list type (in the
old camlp4).
Does this sound correct?
let rec tp_path = function
| <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
| <:ctyp< $tp1$ . $tp2$ >> ->
(match tp_path tp2 with [n] -> n | _ -> assert false) ::
tp_path tp1
| _ -> invalid_arg "tp_path"
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 14:07 ` Joel Reymont
@ 2007-04-30 14:17 ` Nicolas Pouillard
2007-04-30 14:31 ` Joel Reymont
2007-04-30 14:46 ` Joel Reymont
0 siblings, 2 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-04-30 14:17 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
>
> On Apr 30, 2007, at 3:01 PM, Nicolas Pouillard wrote:
>
> > So you have to take the case <:ctyp< $id:i$ >> and then play with `i'
> > that is an ident and can be matched with <:ident< ... >>
>
> It looks like this is being taken care of by the first pattern.
>
> It also looks like the second pattern is matching a list type (in the
> old camlp4).
>
> Does this sound correct?
>
> let rec tp_path = function
> | <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
> | <:ctyp< $tp1$ . $tp2$ >> ->
> (match tp_path tp2 with [n] -> n | _ -> assert false) ::
> tp_path tp1
> | _ -> invalid_arg "tp_path"
>
lid is for lower case identifier it's a string
uid is for upper case identifier it's a string
id is for any identifier it's type is ident
id ::= lid | uid | id1 . id2 | id1 id2
A function like tp_path is can be rewrite by a function that works
only on idents.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 14:17 ` Nicolas Pouillard
@ 2007-04-30 14:31 ` Joel Reymont
2007-04-30 14:46 ` Joel Reymont
1 sibling, 0 replies; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 14:31 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On Apr 30, 2007, at 3:17 PM, Nicolas Pouillard wrote:
> id ::= lid | uid | id1 . id2 | id1 id2
>
> A function like tp_path is can be rewrite by a function that works
> only on idents.
So something like this then?
let rec tp_path = function
| <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id]
| <:ctyp< $id:id$ >> ->
(match id with
| <:ident< $tp1$ . $tp2$ >> ->
(match tp_path tp2 with [n] -> n | _ -> assert false) ::
tp_path tp1
| _ -> invalid_arg "tp_path")
| _ -> invalid_arg "tp_path"
It does compile.
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 14:17 ` Nicolas Pouillard
2007-04-30 14:31 ` Joel Reymont
@ 2007-04-30 14:46 ` Joel Reymont
2007-04-30 15:19 ` Nicolas Pouillard
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 14:46 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
What does this match? I assume that $list...$ is a list but the dot
in the middle throws me off.
| <:ctyp< ! $list:parms$ . $tp$ >> -> poly _loc parms tp
Is this a good translation?
| <:ctyp< ! $id:id$ >> ->
(match id with
| <:ident< $list:params$ . $tp$ >> ->
poly _loc parms tp
| _ -> failwith "fold_tp: unknown type")
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 14:46 ` Joel Reymont
@ 2007-04-30 15:19 ` Nicolas Pouillard
2007-04-30 15:29 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-04-30 15:19 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
> What does this match? I assume that $list...$ is a list but the dot
> in the middle throws me off.
>
> | <:ctyp< ! $list:parms$ . $tp$ >> -> poly _loc parms tp
>
> Is this a good translation?
>
> | <:ctyp< ! $id:id$ >> ->
> (match id with
> | <:ident< $list:params$ . $tp$ >> ->
> poly _loc parms tp
> | _ -> failwith "fold_tp: unknown type")
No, the dot here is not the same it's part of the syntax for rank-2
polymorphism.
t ::= ... | ! 'a ... 'z . t
Having a function to unfold 'a ... 'z to a list.
let unfold_params x =
let rec loop x acc =
match x with
| <:ctyp<>> -> acc
| <:ctyp< $x$ $y$ >> -> loop x (loop y acc)
| x -> x :: acc
in loop x [];;
...
| <:ctyp< ! $params$ . $t$ >> ->
poly _loc (unfold_params params) t
...
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 15:19 ` Nicolas Pouillard
@ 2007-04-30 15:29 ` Joel Reymont
2007-04-30 15:46 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 15:29 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
One last chunk in that huge file...
---
Parse error: Deprecated syntax, the grammar module is expected
Preprocessor error
---
This points at "str" in Pcaml.str_item in DELETE_RULE. How do I fix?
Also, would you have any comments on the code in EXTEND?
Thanks, Joel
---
DELETE_RULE
Pcaml.str_item: "type"; LIST1 Pcaml.type_declaration SEP "and"
END
EXTEND
GLOBAL: Pcaml.str_item;
with_decl:
[[ td = Pcaml.type_declaration; "with"; idl = LIST1 LIDENT SEP ","
-> td, idl
| td = Pcaml.type_declaration -> td, [] ]];
Pcaml.str_item:
[[ "type"; twdl = LIST1 with_decl SEP "and" ->
let tys = List.map fst twdl in
let der_vals, der_tys =
both List.concat List.concat
(List.split (List.map gen_derived_defs twdl)) in
let tydef = <:str_item< type $list:tys @ der_tys$ >> in
let valdef = <:str_item< value rec $list:der_vals$ >> in
match der_vals with
| [] -> tydef
| _ -> <:str_item< declare $tydef$; $valdef$; end >> ]];
Pcaml.str_item:
[[ "SEXP_CONV_PATH"; conv_path = STRING ->
set_conv_path conv_path;
StDcl (_loc, [])
]];
END
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 15:29 ` Joel Reymont
@ 2007-04-30 15:46 ` Nicolas Pouillard
2007-04-30 19:44 ` Joel Reymont
2007-04-30 21:16 ` Joel Reymont
0 siblings, 2 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-04-30 15:46 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
> One last chunk in that huge file...
>
> ---
> Parse error: Deprecated syntax, the grammar module is expected
> Preprocessor error
> ---
>
> This points at "str" in Pcaml.str_item in DELETE_RULE. How do I fix?
>
> Also, would you have any comments on the code in EXTEND?
>
Hum that part is really parsing specific, and my answer is only partial.
The hard point is that there no more a list of type_declaration but a
type_declaration with some `and' nodes to separate them.
open Camlp4.PreCast;;
open Syntax;;
(* now removes all Pcaml. *)
> DELETE_RULE
DELETE_RULE Gram
> Pcaml.str_item: "type"; LIST1 Pcaml.type_declaration SEP "and"
str_item: "type"; type_declaration
> END
You should look at camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
> EXTEND
EXTEND Gram
[...]
> | _ -> <:str_item< declare $tydef$; $valdef$; end >> ]];
| _ -> <:str_item< $tydef$; $valdef$ >> ]];
>
> Pcaml.str_item:
> [[ "SEXP_CONV_PATH"; conv_path = STRING ->
> set_conv_path conv_path;
> StDcl (_loc, [])
<:str_item<>>
> ]];
> END
>
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 15:46 ` Nicolas Pouillard
@ 2007-04-30 19:44 ` Joel Reymont
2007-04-30 21:08 ` Joel Reymont
2007-04-30 21:16 ` Joel Reymont
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 19:44 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
let tuplify_exprs _loc = function
| [] -> assert false
| [expr] -> expr
| exprs -> <:expr< ( $list:exprs$ ) >>
This gives
File "pa_sexp_conv.ml", line 61, characters 26-31:
This expression has type Camlp4.PreCast.Syntax.Ast.expr list
but is here used with type Camlp4.PreCast.Syntax.Ast.ident list
Previously, I replaced $list:tys$ with $tup:tys$ in the ctyp context.
What do I need to use above?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 19:44 ` Joel Reymont
@ 2007-04-30 21:08 ` Joel Reymont
2007-05-01 7:20 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 21:08 UTC (permalink / raw)
To: Nicolas Pouillard, Caml List
This replacement compiles.
Should I assume it to be correct?
let tuplify_exprs _loc = function
| [] -> assert false
| [expr] -> expr
| exprs -> <:expr< ( exprs ) >>
On Apr 30, 2007, at 8:44 PM, Joel Reymont wrote:
> let tuplify_exprs _loc = function
> | [] -> assert false
> | [expr] -> expr
> | exprs -> <:expr< ( $list:exprs$ ) >>
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 15:46 ` Nicolas Pouillard
2007-04-30 19:44 ` Joel Reymont
@ 2007-04-30 21:16 ` Joel Reymont
1 sibling, 0 replies; 29+ messages in thread
From: Joel Reymont @ 2007-04-30 21:16 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
| <:ctyp< $id:id$ >> ->
(match id with
| <:ident< $tp1$ . $tp2$ >> ->
(match tp_path tp2 with [n] -> n | _ -> assert false) ::
tp_path tp1
| _ -> invalid_arg "tp_path")
<:ident ... >> above apparently made tp1 and tp2 into idents. How do
I convert them to ctyp as the error below requires?
This expression has type
Camlp4.PreCast.Syntax.Ast.ident = Camlp4.PreCast.Ast.ident
but is here used with type
Camlp4.PreCast.Syntax.Ast.ctyp = Camlp4.PreCast.Ast.ctyp
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-04-30 21:08 ` Joel Reymont
@ 2007-05-01 7:20 ` Nicolas Pouillard
2007-05-01 13:21 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 7:20 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 4/30/07, Joel Reymont <joelr1@gmail.com> wrote:
> This replacement compiles.
>
> Should I assume it to be correct?
>
> let tuplify_exprs _loc = function
> | [] -> assert false
> | [expr] -> expr
> | exprs -> <:expr< ( exprs ) >>
No that one is not correct your are building the program with the free
variable `exprs'.
The correct code should be:
| expr :: exprs -> <:expr< ( $expr$, $list:exprs$ ) >>
Which is a sugar for:
| expr :: exprs -> <:expr< ( $expr$, $Ast.exCom_of_list exprs$ ) >>
Alas camlp4of seems to don't support that sugar well, so fall back the
second one.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 7:20 ` Nicolas Pouillard
@ 2007-05-01 13:21 ` Joel Reymont
2007-05-01 13:35 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 13:21 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
Nicolas,
Thank you for your patience!
As per your suggestion, I converted this
| <:ctyp< ( $list:tys$ ) >> -> tupl _loc (List.map aux tys)
into this
| <:ctyp< ( $tup:tys$ ) >> -> tupl _loc (List.map aux
(list_of_ctyp tys []))
where tupl is actually sexp_of_tuple below.
The ultimate goal is to convert ( t1 * ... * tN ) into a Lisp-style
(t1, ..., tN).
My next issue is an error in sex_of_tuple:
This expression has type
(Camlp4.PreCast.Syntax.Ast.patt * Camlp4.PreCast.Syntax.Ast.expr)
list
but is here used with type Camlp4.PreCast.Syntax.Ast.binding list
This points at $list:bindings$. I attached mk_bindings at the end, in
case it's of any use.
How should I rewrite $list:bindings$ here?
I don't understand why $list:bindings$ is assumed to be of type
binding list when bindings itself is [(patt, expr)].
Thanks, Joel
---
(* Conversion of tuples *)
let sexp_of_tuple _loc fps =
let bindings, patts, vars = Gen.mk_bindings _loc fps in
let expr =
<:expr<
let $list:bindings$ in
Sexplib.Sexp.List $Gen.mk_expr_lst _loc vars$
>>
in
let matching =
(
<:patt< ( $list:patts$ ) >>,
None,
expr
)
in
`Match [matching]
(* [mk_rev_bindings _loc fps] takes a list of values of the form
[`Fun fun_expr] and [`Match matching]. [fun_expr] is an
expression
denoting a function, and [matching] is a list of bindings. @return
the tuple [(bindings, patts, var_exprs)], where [bindings] is a
list
of [(pattern, expression)] tuples, [patts] is the list of those
patterns, and [var_exprs] is the expression (variable) associated
with each of those patterns. The resulting lists are reversed. *)
let mk_rev_bindings _loc fps =
let coll (i, bindings, patts, vars) fp =
let name = "v" ^ string_of_int i in
let var_expr = ide _loc name in
let expr =
match fp with
| `Fun fun_expr -> <:expr< $fun_expr$ $var_expr$ >>
| `Match matchings ->
<:expr< match $var_expr$ with [ $list:matchings$ ] >>
in
let patt = idp _loc name in
i - 1, (patt, expr) :: bindings, patt :: patts, var_expr ::
vars in
let n = List.length fps in
let _, bindings, patts, vars =
List.fold_left coll (n, [], [], []) fps in
bindings, patts, vars
(* [mk_bindings _loc fps] same as [mk_rev_bindings] but the resulting
lists are in order. *)
let mk_bindings _loc fps = mk_rev_bindings _loc (List.rev fps)
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 13:21 ` Joel Reymont
@ 2007-05-01 13:35 ` Nicolas Pouillard
2007-05-01 13:54 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 13:35 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
> Nicolas,
>
[...]
> This expression has type
> (Camlp4.PreCast.Syntax.Ast.patt * Camlp4.PreCast.Syntax.Ast.expr)
> list
> but is here used with type Camlp4.PreCast.Syntax.Ast.binding list
Before bindings was just a (patt * expr) list, now there is a binding type:
bi := (* empty *) | patt = expr | bi1 and bi2
So where you see (p, e) you can write <:binding< $p$ = $e$ >>.
You can put a binding in a let, for instance: <:expr< let $bi$ in $e$
>> if you want put a list of bindings you can write <:expr< let
$list:bis$ in $e$ >>.
But perhaps it should be better to avoid useless conversion to/from lists.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 13:35 ` Nicolas Pouillard
@ 2007-05-01 13:54 ` Joel Reymont
2007-05-01 14:16 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 13:54 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On May 1, 2007, at 2:35 PM, Nicolas Pouillard wrote:
> So where you see (p, e) you can write <:binding< $p$ = $e$ >>.
I took care of the issue by using the above at the source that
generated bindings.
In the same sexp_of_tuple there's
let matching =
(
<:patt< ( $list:patts$ ) >>,
None,
expr
)
in
`Match [matching]
which gives the following error on $list:patts$
--
This expression has type Camlp4.PreCast.Syntax.Ast.patt list
but is here used with type Camlp4.PreCast.Syntax.Ast.ident list
--
patts is [patt] where "patt = idp _loc name" and "idp _loc id =
<:patt< $lid:id$ >>"
I'm guessing that $list always represents "ident list" so it can't be
used here.
What should be used instead?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 13:54 ` Joel Reymont
@ 2007-05-01 14:16 ` Nicolas Pouillard
2007-05-01 14:31 ` Joel Reymont
2007-05-01 16:05 ` Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
0 siblings, 2 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 14:16 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
>
> On May 1, 2007, at 2:35 PM, Nicolas Pouillard wrote:
>
> > So where you see (p, e) you can write <:binding< $p$ = $e$ >>.
>
> I took care of the issue by using the above at the source that
> generated bindings.
>
> In the same sexp_of_tuple there's
>
> let matching =
> (
> <:patt< ( $list:patts$ ) >>,
> None,
> expr
> )
> in
> `Match [matching]
Here there is two things. The first one is about $list:patts$ that is
like the problem with tuples, so you can use <:patt< (
$tup:Ast.paCom_of_list patts$ ) >>.
The second one is about match cases, the old type was (patt * expr
option * expr) list, now it's match_case
match_case, mc ::= (* empty *)
| mc1 | mc2
| p -> e
| p when e1 -> e2
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 14:16 ` Nicolas Pouillard
@ 2007-05-01 14:31 ` Joel Reymont
2007-05-01 15:49 ` Nicolas Pouillard
2007-05-01 16:05 ` Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 14:31 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
Moving on! I hope this long thread will be instructive for later
Google searches.
(* Get the path associated with a polymorphic type *)
let rec get_appl_path _loc = function
| <:ctyp< $lid:_$ >> as tp -> tp
| <:ctyp< $_$ . $_$ >> as tp -> tp
| <:ctyp< $tp$ $_$ >> -> get_appl_path _loc tp
| _ -> failwith "get_appl_path: unknown type"
File "pa_sexp_conv.ml", line 320, characters 22-25:
While expanding quotation "ctyp" in a position of "patt":
Parse error: ident_of_ctyp: this type is not an identifier
That would be <:ctyp< $_$ . $_$ >> as tp -> tp
It would work (from what I understand) if it was <:ctyp< ! $_$ . $_$
>> but what does this match and how to fix it?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 14:31 ` Joel Reymont
@ 2007-05-01 15:49 ` Nicolas Pouillard
2007-05-01 16:14 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 15:49 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
> Moving on! I hope this long thread will be instructive for later
> Google searches.
>
> (* Get the path associated with a polymorphic type *)
> let rec get_appl_path _loc = function
> | <:ctyp< $lid:_$ >> as tp -> tp
> | <:ctyp< $_$ . $_$ >> as tp -> tp
> | <:ctyp< $tp$ $_$ >> -> get_appl_path _loc tp
> | _ -> failwith "get_appl_path: unknown type"
>
> File "pa_sexp_conv.ml", line 320, characters 22-25:
> While expanding quotation "ctyp" in a position of "patt":
> Parse error: ident_of_ctyp: this type is not an identifier
>
> That would be <:ctyp< $_$ . $_$ >> as tp -> tp
>
> It would work (from what I understand) if it was <:ctyp< ! $_$ . $_$
> >> but what does this match and how to fix it?
>
> Thanks, Joel
>
No there is a difference between <:ctyp< ! 'a ... 'z . typ >> and
<:ctyp< id1.id2 >> the first one means forall, the second one is the
access of the `id2' field of the module `id1'.
The goal the function get_appl_path is to get the type constructor, so
go down left into all type applications.
Reminder, type application depends on the syntax:
original syntax: int list, (string, int list) Hashtbl.t
revised syntax: list int, Hashtbl.t string (list int)
If I well remember, you use camlp4of, so that's the original syntax.
Then you should go right in application nodes: <:ctyp< $_$ $t$ >>.
let rec get_appl_path _loc = function
| <:ctyp< $id:i$ >> -> i
| <:ctyp< $_$ $tp$ >> -> get_appl_path _loc tp
| _ -> failwith "get_appl_path: unknown type"
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 14:16 ` Nicolas Pouillard
2007-05-01 14:31 ` Joel Reymont
@ 2007-05-01 16:05 ` Joel Reymont
2007-05-01 16:19 ` Nicolas Pouillard
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 16:05 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On May 1, 2007, at 3:16 PM, Nicolas Pouillard wrote:
> The second one is about match cases, the old type was (patt * expr
> option * expr) list, now it's match_case
>
> match_case, mc ::= (* empty *)
> | mc1 | mc2
> | p -> e
> | p when e1 -> e2
Then
let matching =
(
<:patt< ( $tup:Ast.paCom_of_list patts$ ) >>,
None,
expr
)
becomes
let patt = <:patt< ( $tup:Ast.paCom_of_list patts$ ) >> in
<:match_case< $patt$ -> $expr$ >>
Right?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 15:49 ` Nicolas Pouillard
@ 2007-05-01 16:14 ` Joel Reymont
2007-05-01 16:27 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 16:14 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
RfTag is gone, apparently. How do you process variants then?
The only reference to constructors I could find is with_constr in
Camlp4Ast.partial.ml. It's applicable to modules, apparently.
The original code is attached below.
Thanks, Joel
---
and sexp_of_variants_loop _loc acc = function
| RfTag (cnstr, _, []) ->
(
<:patt< `$cnstr$ >>,
None,
<:expr< Sexplib.Sexp.Atom $str:cnstr$ >>
) :: acc
| RfTag (cnstr, _, tps) ->
let fps = List.map (sexp_of_type _loc) tps in
let bindings, patts, vars = Gen.mk_bindings _loc fps in
let arg_patt = tuplify_patts _loc patts in
let cnstr_expr = <:expr< Sexplib.Sexp.Atom $str:cnstr$ >> in
(
<:patt< `$cnstr$ $arg_patt$ >>,
None,
<:expr<
let $list:bindings$ in
Sexplib.Sexp.List $Gen.mk_expr_lst _loc (cnstr_expr ::
vars)$
>>
) :: acc
| RfInh (TyVrn (_loc, row_fields, _)) ->
List.fold_left (sexp_of_variants_loop _loc) acc row_fields
| RfInh tp ->
let tp_path, call =
match tp with
| <:ctyp< $tp1$ $tp2$ >> ->
let fp1 = sexp_of_type _loc tp1 in
let fp2 = sexp_of_type _loc tp2 in
let tp_path = List.rev (Gen.tp_path (get_appl_path
_loc tp1)) in
let expr = sexp_of_appl_fun _loc fp1 fp2 in
tp_path, expr
| _ ->
let tp_path = Gen.tp_path tp in
match tp_path with
| tn :: path -> tp_path, mk_abst_call _loc tn path
| [] -> assert false (* impossible *)
in
(
<:patt< (#$tp_path$ as v) >>,
None,
<:expr< $call$ v >>
) :: acc
and sexp_of_variant _loc row_fields =
`Match (
List.rev (List.fold_left (sexp_of_variants_loop _loc) []
row_fields))
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:05 ` Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
@ 2007-05-01 16:19 ` Nicolas Pouillard
0 siblings, 0 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 16:19 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
>
> On May 1, 2007, at 3:16 PM, Nicolas Pouillard wrote:
>
> > The second one is about match cases, the old type was (patt * expr
> > option * expr) list, now it's match_case
> >
> > match_case, mc ::= (* empty *)
> > | mc1 | mc2
> > | p -> e
> > | p when e1 -> e2
>
> Then
>
> let matching =
> (
> <:patt< ( $tup:Ast.paCom_of_list patts$ ) >>,
> None,
> expr
> )
>
> becomes
>
> let patt = <:patt< ( $tup:Ast.paCom_of_list patts$ ) >> in
> <:match_case< $patt$ -> $expr$ >>
>
> Right?
Or even shorter:
<:match_case< ( $tup:Ast.paCom_of_list patts$ ) -> $expr$ >>
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:14 ` Joel Reymont
@ 2007-05-01 16:27 ` Nicolas Pouillard
2007-05-01 16:35 ` Joel Reymont
2007-05-01 17:04 ` camlp4 3.10: Matching variant types Joel Reymont
0 siblings, 2 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 16:27 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
> RfTag is gone, apparently. How do you process variants then?
>
> The only reference to constructors I could find is with_constr in
> Camlp4Ast.partial.ml. It's applicable to modules, apparently.
For variants you have:
type, t ::= ... | `id | `id of t | `id of & t | t & t
<< `id >> was encoded as RfTag(_loc, true, [])
<< `id of t1 & ... & tN >> by RfTag(_loc, false, [t1; ...; tN])
<< `id of & t1 & ... & tN >> by RfTag(_loc, true, [t1; ...; tN])
However I suggest you comment that part and try to go further with
poly variants at a first glance.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:27 ` Nicolas Pouillard
@ 2007-05-01 16:35 ` Joel Reymont
2007-05-01 16:39 ` Nicolas Pouillard
2007-05-01 17:04 ` camlp4 3.10: Matching variant types Joel Reymont
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 16:35 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On May 1, 2007, at 5:27 PM, Nicolas Pouillard wrote:
> However I suggest you comment that part and try to go further with
> poly variants at a first glance.
Are you saying that RfTag used to apply to regular variants?
What about RfInh, how is that encoded now? Is this what you referred
to as poly variants?
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:35 ` Joel Reymont
@ 2007-05-01 16:39 ` Nicolas Pouillard
2007-05-01 16:50 ` Joel Reymont
0 siblings, 1 reply; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 16:39 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
>
> On May 1, 2007, at 5:27 PM, Nicolas Pouillard wrote:
>
> > However I suggest you comment that part and try to go further with
> > poly variants at a first glance.
>
> Are you saying that RfTag used to apply to regular variants?
>
> What about RfInh, how is that encoded now? Is this what you referred
> to as poly variants?
No, no, no there is still a difference between poly variants and classic ones.
When I wrote `id it's for polymorphic ones.
However there are now all in the same category: ctyp, so inherit is
useless since it was made to be able to inject a type name in a
polymorphic declaration.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:39 ` Nicolas Pouillard
@ 2007-05-01 16:50 ` Joel Reymont
2007-05-01 17:13 ` Nicolas Pouillard
0 siblings, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 16:50 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On May 1, 2007, at 5:39 PM, Nicolas Pouillard wrote:
> No, no, no there is still a difference between poly variants and
> classic ones.
>
> When I wrote `id it's for polymorphic ones.
Then I would use <:ctyp< $id$ >> to match variants and `id to match
poly variants, right?
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* camlp4 3.10: Matching variant types
2007-05-01 16:27 ` Nicolas Pouillard
2007-05-01 16:35 ` Joel Reymont
@ 2007-05-01 17:04 ` Joel Reymont
2007-05-03 5:58 ` [Caml-list] " Dmitry Bely
1 sibling, 1 reply; 29+ messages in thread
From: Joel Reymont @ 2007-05-01 17:04 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: Caml List
On May 1, 2007, at 5:27 PM, Nicolas Pouillard wrote:
> << `id >> was encoded as RfTag(_loc, true, [])
So then "RfTag (cnstr, _, [])", a constructor without arguments,
would become <:ctyp< $`id$ >> whereas "RfTag (cnstr, _, tps)" <:ctyp<
$id:tys$ >>?
Wasn't <:ctyp< $id$ >> used for something else already?
camlp4of -str '<:ctyp< int >>'
Ast.TyId (_loc, Ast.IdLid (_loc, "int"))
I thought that id is used for regular types, according to the above.
I tried to see what variant type defs expand to (below).
camlp4of -str '<:ctyp< [`Foo] >>'
Ast.TyVrnEq (_loc, Ast.TyVrn (_loc, "Foo"))
camlp4of -str '<:ctyp< [Foo] >>'
Ast.TyVrnEq (_loc, Ast.TyId (_loc, Ast.IdUid (_loc, "Foo")))
camlp4of -str '<:ctyp< [`Foo|`Bar] >>'
Ast.TyVrnEq (_loc,
Ast.TyOr (_loc, Ast.TyVrn (_loc, "Foo"), Ast.TyVrn (_loc, "Bar")))
camlp4of -str '<:ctyp< [Foo|Bar] >>'
Ast.TyVrnEq (_loc,
Ast.TyOr (_loc, Ast.TyId (_loc, Ast.IdUid (_loc, "Foo")),
Ast.TyId (_loc, Ast.IdUid (_loc, "Bar"))))
Is there a "ctyp", "id", "lid", etc. shortcut that should be used for
TyVrnEq? Is there a path through the camlp4 sources that would enable
me to figure this out?
Ast.TyId (_loc, Ast.IdUid (_loc, "Foo")
This is matched by $id:uid", correct?
Is there a "shortcut" for TyOr and TyVrn?
I'm afraid I'm still lost here, thus my asking for more information.
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Upgrading sexplib-2.7.0 to camlp4 3.10
2007-05-01 16:50 ` Joel Reymont
@ 2007-05-01 17:13 ` Nicolas Pouillard
0 siblings, 0 replies; 29+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 17:13 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
>
> On May 1, 2007, at 5:39 PM, Nicolas Pouillard wrote:
>
> > No, no, no there is still a difference between poly variants and
> > classic ones.
> >
> > When I wrote `id it's for polymorphic ones.
>
> Then I would use <:ctyp< $id$ >> to match variants and `id to match
> poly variants, right?
To be consistent on notations
<:ctyp< $id$ >> to match variants
<:ctyp< `$id$ >> to match polymorphic variants
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [Caml-list] camlp4 3.10: Matching variant types
2007-05-01 17:04 ` camlp4 3.10: Matching variant types Joel Reymont
@ 2007-05-03 5:58 ` Dmitry Bely
0 siblings, 0 replies; 29+ messages in thread
From: Dmitry Bely @ 2007-05-03 5:58 UTC (permalink / raw)
To: Caml List
Probably the following is related to Joel's questions on variant type
matching. I am trying to convert IoXML syntax extension to the new
camlp4. Currently I am stuck here:
...
value gen_output_cons (loc, c, tl) =
let p =
let p = <:patt< $uid:c$ >> in
let (p, _) =
List.fold_left
(fun (p, cnt) _ ->
let p = <:patt< $p$ $lid:pname cnt$ >> in
(p, cnt + 1))
(p, 1) tl
in
p
in
let e = gen_xprint_cons loc c tl in
(p, None, e)
;
...
value gen_output_sum loc cdl =
let mc =
List.fold_right
(fun cd mc ->
let (p, _, e) = gen_output_cons cd in
<:match_case< $p$ -> $e$ | $mc$ >>)
cdl <:match_case<>> in
<:expr< fun ppf -> fun [ $mc$ ] >>
;
...
value gen_output_funs loc tdl sil =
let pel =
List.fold_right
(fun ((loc, n), tpl, tk, cl) pel ->
let body =
loop tk where rec loop =
fun
[ <:ctyp< [ $cdl$ ] >> -> gen_output_sum loc cdl
File "pa_ioXML.ml", line 257, characters 58-61:
This expression has type Camlp4.PreCast.Ast.ctyp but is here used with type
(Camlp4.PreCast.Ast.Loc.t * string * Camlp4.PreCast.Ast.ctyp list) list
As usual: (cdl) was a list before, now it is not. Is were a simple way
to get a list and make (gen_output_sum) happy? Or this should be
complete rewritten - how?
- Dmitry Bely
^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2007-05-03 5:59 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-30 13:55 Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
2007-04-30 14:01 ` Nicolas Pouillard
2007-04-30 14:07 ` Joel Reymont
2007-04-30 14:17 ` Nicolas Pouillard
2007-04-30 14:31 ` Joel Reymont
2007-04-30 14:46 ` Joel Reymont
2007-04-30 15:19 ` Nicolas Pouillard
2007-04-30 15:29 ` Joel Reymont
2007-04-30 15:46 ` Nicolas Pouillard
2007-04-30 19:44 ` Joel Reymont
2007-04-30 21:08 ` Joel Reymont
2007-05-01 7:20 ` Nicolas Pouillard
2007-05-01 13:21 ` Joel Reymont
2007-05-01 13:35 ` Nicolas Pouillard
2007-05-01 13:54 ` Joel Reymont
2007-05-01 14:16 ` Nicolas Pouillard
2007-05-01 14:31 ` Joel Reymont
2007-05-01 15:49 ` Nicolas Pouillard
2007-05-01 16:14 ` Joel Reymont
2007-05-01 16:27 ` Nicolas Pouillard
2007-05-01 16:35 ` Joel Reymont
2007-05-01 16:39 ` Nicolas Pouillard
2007-05-01 16:50 ` Joel Reymont
2007-05-01 17:13 ` Nicolas Pouillard
2007-05-01 17:04 ` camlp4 3.10: Matching variant types Joel Reymont
2007-05-03 5:58 ` [Caml-list] " Dmitry Bely
2007-05-01 16:05 ` Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
2007-05-01 16:19 ` Nicolas Pouillard
2007-04-30 21:16 ` Joel Reymont
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox