Commits

camlspotter committed b5337d9

ovisit is impure, since ofold provides pure ovisit

Comments (0)

Files changed (2)

pa/pa_ovisitor.ml

         if not (StringMap.mem (label_of_path id) !used) then
           used := StringMap.add (label_of_path id) 0 !used;
         Some <:expr@loc< self # $label_of_path id$ >>
-    | (TyQuo (loc, _) as tv) -> Some <:expr@loc< $ expr_of_tvar tv $ self >>
+    | (TyQuo (_loc, _) as tv) -> Some (expr_of_tvar tv)
     | TyApp (loc, (TyId(_, id) as f), args) ->  (* (int, float) Hashtbl.t *)
         let args = list_of_ctyp args [] in
         used := StringMap.add (label_of_path id) (List.length args) !used;
         | None -> None
         | Some f -> 
             Some (Gen.apply loc f (List.map (fun x -> match gen_ctyp x with 
-            | None -> <:expr<fun self _ -> self>> 
-            | Some f -> <:expr< fun self -> $f$ >> ) args))
+            | None -> <:expr<fun _ -> ()>> 
+            | Some f -> f ) args))
         end
     | TyApp (loc, TyApp (_loc, f, args1), args2) -> 
         gen_ctyp (TyApp (loc, f, TyCom(_loc, args1, args2)))
     | _ -> assert false
   
   and gen_let_seq ctyps exps = match ctyps, exps with
-    | [], [] -> <:expr< self >>
+    | [], [] -> <:expr< () >>
     | (ctyp::ctyps), (exp::exps) ->
         begin match gen_ctyp ctyp with
         | None -> gen_let_seq ctyps exps
-        | Some f -> <:expr< let self = $f$ $exp$ in $ gen_let_seq ctyps exps $ >>
+        | Some f -> <:expr< $f$ $exp$ ; $ gen_let_seq ctyps exps $ >>
         end
     | _ -> assert false
   
     | None -> <:expr< >>
     | Some f -> <:expr< fun __value -> $f$ __value >>
   
-  let is_just_self_case = function
-    | <:match_case< $_$ -> self >> -> true
+  let is_just_unit_case = function
+    | <:match_case< $_$ -> () >> -> true
     | _ -> false
   
   let sum _name _loc ctyp = 
       let ids = mk_idents "__x" (List.length ctyps) in
       let patt = create_patt_app (PaId(locId, id)) (List.map patt_of_id ids) in
       let exp = match ids with
-        | [] -> <:expr< self >>
+        | [] -> <:expr< () >>
         | _ -> gen_let_seq ctyps (List.map expr_of_id ids)
       in
       <:match_case@locOf< $ patt $ -> $ exp $ >>
         | _ -> assert false
       ) constrs 
     in
-    if List.for_all is_just_self_case cases then
-      <:expr< fun __value -> self >>
+    if List.for_all is_just_unit_case cases then
+      <:expr< fun __value -> () >>
     else
       <:expr< fun __value -> match __value with $mcOr_of_list cases$ >>
   
     let mems = List.map (fun l -> <:expr< __value.$id:l$ >> ) labs in 
     <:expr< fun __value -> $gen_let_seq ctyps mems $ >>
     
-  (** for [X; Y; .. ] and BASE, build ('self -> X -> 'self) -> ('self -> Y -> 'self) -> ... -> BASE *)
+  (** for [X; Y; .. ] and BASE, build (X -> unit) -> (Y -> unit) -> ... -> BASE *)
   let dispatch_type params base = 
-    List.fold_right (fun ctyp st -> <:ctyp< ('self -> $ctyp$ -> 'self) -> $st$ >>) params base
+    List.fold_right (fun ctyp st -> <:ctyp< ($ctyp$ -> unit) -> $st$ >>) params base
   
   let method_type params name = 
-    create_for_all params (dispatch_type params <:ctyp< $ create_param_type params name $ -> 'self >>)
+    create_for_all params (dispatch_type params <:ctyp< $ create_param_type params name $ -> unit >>)
   
   
   (******************* kind of template *)
       in
       let methods = concat_class_str_items (vmethods @ methods) in
 
+      no_visit_idents := [];
+
       (* We use the name of the first type for the class name prefix *)
       make_classes ~virt:(vmethods <> []) []
         "ovisit_" decls 
-        <:class_expr<object (self:'self) $methods$ end>>
+        <:class_expr<object (self) $methods$ end>>
     )
   ;;
 end
       in
       let methods = concat_class_str_items (vmethods @ methods) in
 
+      no_visit_idents := [];
+
       (* We use the name of the first type for the class name prefix *)
       make_classes ~virt:(vmethods <> []) [ <:ctyp<'st>> ]
         "ofold_" decls 
       in
       let methods = concat_class_str_items (vmethods @ methods) in
 
+      no_visit_idents := [];
+
       make_classes ~virt:(vmethods <> []) []
         "omap_" decls 
         <:class_expr<object (self:'self) $methods$ end>>

pa/test/OMakefile

 
 Test(test_fold)
 Test(test_iter)
+Test(test_readme)
 
 AutoClean()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.