<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/10/9ff40d06808df7ebb5d336e0f03fc68b"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-10-03T17:28:00"
  subject="Re: [Caml-list] Generation of Java code from OCaml"
  prev="2009/10/bdaff94c0ba36d59e0c3bee8f4d5e4b2"
  next="2009/10/970c5b49cb35ab3fae6528efb851857c"
  prev-in-thread="2009/10/bdaff94c0ba36d59e0c3bee8f4d5e4b2"
  next-in-thread="2009/10/970c5b49cb35ab3fae6528efb851857c"
  prev-thread="2009/09/73ef227324d51c3763375d0428a2233a"
  next-thread="2009/09/e654e44c4c8eec753dff6cd3c7c52d68"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Generation of Java code from OCaml">
<msg 
  url="2009/09/4e92d2c97f93cc2b345ed338517d4b92"
  from="Mykola Stryebkov &lt;nick@m...&gt;"
  author="Mykola Stryebkov"
  date="2009-09-23T18:15:16"
  subject="Generation of Java code from OCaml">
<msg 
  url="2009/09/7da295604997571a18bcd51a8146b2ee"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-09-23T19:57:16"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/4836b7a977687ee8e9e0ee3f27cba4a1"
  from="Mykola Stryebkov &lt;nick@m...&gt;"
  author="Mykola Stryebkov"
  date="2009-09-23T22:54:24"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/6bd9fd91721ef76b3401a60d460742d8"
  from="David Allsopp &lt;dra-news@m...&gt;"
  author="David Allsopp"
  date="2009-09-24T08:04:08"
  subject="RE: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/e91074dc599ff6e957de727792621cf3"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-09-24T09:45:32"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/32eba4e3114fc90a6f702c5c4797299f"
  from="Martin Jambon &lt;martin.jambon@e...&gt;"
  author="Martin Jambon"
  date="2009-09-24T11:26:31"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/fb85714bd6ba2b1bdabe4635306284f7"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-09-24T12:02:17"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/09/8dc69d73f35aab73e2917c4e09adb471"
  from="Martin Jambon &lt;martin.jambon@e...&gt;"
  author="Martin Jambon"
  date="2009-09-24T12:27:45"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/10/bdaff94c0ba36d59e0c3bee8f4d5e4b2"
  from="Anil Madhavapeddy &lt;anil@r...&gt;"
  author="Anil Madhavapeddy"
  date="2009-10-03T12:16:28"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/10/9ff40d06808df7ebb5d336e0f03fc68b"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-10-03T17:28:00"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
<msg 
  url="2009/10/970c5b49cb35ab3fae6528efb851857c"
  from="Anil Madhavapeddy &lt;anil@r...&gt;"
  author="Anil Madhavapeddy"
  date="2009-10-03T18:29:28"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/09/43e425986cb065c18ef92743b32cb74b"
  from="ygrek &lt;ygrekheretix@g...&gt;"
  author="ygrek"
  date="2009-09-26T07:37:49"
  subject="Re: [Caml-list] Generation of Java code from OCaml">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Sat, Oct 3, 2009 at 2:16 PM, Anil Madhavapeddy &lt;anil@recoil.org&gt; wrote:
&gt; The only thing I haven't quite worked out yet is the quotation to
&gt; pattern-match type applications to detect things like "(string, unit)
&gt; Hashtbl.t" the way the current json-static does via the grammar extension.
&gt; -anil

Below are two patches (from `git log -u`) adding the relevant features.

##########################
diff --git a/json-static/pa_json_tc.ml b/json-static/pa_json_tc.ml
index f1d21e7..09b7937 100644
--- a/json-static/pa_json_tc.ml
+++ b/json-static/pa_json_tc.ml
@@ -494,11 +494,15 @@ and process_td _loc = function
  | &lt;:ctyp&lt; int64 &gt;&gt; -&gt; Int64
  | &lt;:ctyp&lt; unit &gt;&gt; -&gt; Unit
  | &lt;:ctyp&lt; char &gt;&gt; -&gt; Char
+ | &lt;:ctyp&lt; number &gt;&gt; -&gt; Number

  | &lt;:ctyp&lt; option $t$ &gt;&gt; -&gt; Option (_loc, process_td _loc t)
  | &lt;:ctyp&lt; list $t$ &gt;&gt; -&gt; List (_loc, process_td _loc t)
  | &lt;:ctyp&lt; array $t$ &gt;&gt; -&gt; Array (_loc, process_td _loc t)
-
+ | &lt;:ctyp&lt; assoc $t$ &gt;&gt; as assoc -&gt;
+   (match t with
+      | &lt;:ctyp&lt; (string * $t$) &gt;&gt; -&gt; Assoc (_loc, process_td _loc t)
+      | _ -&gt; failwith "must be of the form (string * ...) assoc")
  | &lt;:ctyp&lt; &lt; $cs$ &gt; &gt;&gt; -&gt; Object (process_fields _loc cs)
  | &lt;:ctyp&lt; { $cs$ } &gt;&gt; -&gt; Record (process_fields _loc cs)

@@ -512,8 +516,13 @@ and process_td _loc = function
        (Ast.list_of_ctyp tp []) in
    Tuple tps

- | &lt;:ctyp&lt; $uid:id$.t &gt;&gt; -&gt; Custom id (* XXX broken, how to check for TyApp? *)
+ | &lt;:ctyp&lt; Hashtbl.t string $x$ &gt;&gt; -&gt; Hashtbl (_loc, process_td _loc x)
+ | &lt;:ctyp&lt; json_type &gt;&gt;
+ | &lt;:ctyp&lt; Json_type.json_type &gt;&gt;
+ | &lt;:ctyp&lt; Json_type.t &gt;&gt;
+   -&gt; Raw
  | &lt;:ctyp&lt; $lid:id$ &gt;&gt; -&gt; Name id
+ | &lt;:ctyp&lt; $uid:id$.t &gt;&gt; -&gt; Custom id
  | _ -&gt; failwith "unknown type"

 open Pa_type_conv


##########################
diff --git a/json-static/check.ml b/json-static/check.ml
index 19bac81..ff0186b 100644
--- a/json-static/check.ml
+++ b/json-static/check.ml
@@ -33,3 +33,4 @@ and b = int

 type json c = (string * d * d) list
 and d = [ `A ]
+
diff --git a/json-static/check_tc.ml b/json-static/check_tc.ml
index b362ad2..3105800 100644
--- a/json-static/check_tc.ml
+++ b/json-static/check_tc.ml
@@ -31,3 +31,6 @@ let _ =
   assert (json_o#foo = o#foo);
   assert (json_o#bar = o#bar);
   prerr_endline json_string
+
+type c = (string, unit) Hashtbl.t with json
+type d = (string * float) assoc with json
diff --git a/json-static/pa_json_tc.ml b/json-static/pa_json_tc.ml
index 09b7937..5c76819 100644
--- a/json-static/pa_json_tc.ml
+++ b/json-static/pa_json_tc.ml
@@ -448,6 +448,9 @@ let expand_typedefs _loc l =
   let tojson = make_tojson _loc l in
   &lt;:str_item&lt; $ofjson$; $tojson$ &gt;&gt;

+let type_fail ctyp msg =
+  Loc.raise (Ast.loc_of_ctyp ctyp) (Failure msg)
+
 let rec process_tds tds =
   let rec fn ty =
     match ty with
@@ -455,7 +458,7 @@ let rec process_tds tds =
        fn tyl @ (fn tyr)
     |Ast.TyDcl (_loc, id, _, ty, []) -&gt;
        [ (_loc, id ) , (_loc, process_td _loc ty) ]
-    |_ -&gt; failwith "process_tds: unexpected type"
+    | other -&gt; type_fail other "process_tds: unexpected AST"
    in fn tds

 and process_fields _loc cs =
@@ -463,7 +466,7 @@ and process_fields _loc cs =
     | &lt;:ctyp&lt; $t1$; $t2$ &gt;&gt; -&gt; fn t1 @ (fn t2)
     | &lt;:ctyp&lt; $lid:id$ : mutable $t$ &gt;&gt; -&gt; fnt ~mut:true ~id ~t
     | &lt;:ctyp&lt; $lid:id$ : $t$ &gt;&gt; -&gt;  fnt ~mut:false ~id ~t
-    | _ -&gt; failwith "unexpected ast"
+    | other -&gt; type_fail other "process_fields: unexpected AST"
   and fnt ~mut ~id ~t =
     [ { field_caml_name = id; field_json_name = id;
         field_type = (_loc, process_td _loc t);
@@ -482,7 +485,7 @@ and process_constructor _loc rf =
     | &lt;:ctyp&lt; $uid:id$ &gt;&gt; -&gt;
        { cons_caml_name=id; cons_json_name=id; cons_caml_loc=_loc;
          cons_json_loc=_loc; cons_args=[] }
-    | _ -&gt; failwith "process_constructor: unexpected AST"
+    | other -&gt; type_fail other "process_constructor: unexpected AST"
   ) (Ast.list_of_ctyp rf [])

 and process_td _loc = function
@@ -502,7 +505,7 @@ and process_td _loc = function
  | &lt;:ctyp&lt; assoc $t$ &gt;&gt; as assoc -&gt;
    (match t with
       | &lt;:ctyp&lt; (string * $t$) &gt;&gt; -&gt; Assoc (_loc, process_td _loc t)
-      | _ -&gt; failwith "must be of the form (string * ...) assoc")
+      | other -&gt; type_fail assoc "must be of the form (string * ...) assoc")
  | &lt;:ctyp&lt; &lt; $cs$ &gt; &gt;&gt; -&gt; Object (process_fields _loc cs)
  | &lt;:ctyp&lt; { $cs$ } &gt;&gt; -&gt; Record (process_fields _loc cs)

@@ -523,7 +526,7 @@ and process_td _loc = function
    -&gt; Raw
  | &lt;:ctyp&lt; $lid:id$ &gt;&gt; -&gt; Name id
  | &lt;:ctyp&lt; $uid:id$.t &gt;&gt; -&gt; Custom id
- | _ -&gt; failwith "unknown type"
+ | other -&gt; type_fail other "unknown type"

 open Pa_type_conv
 let _ =

</contents>

</message>

