camlspotter avatar camlspotter committed 997a1a7

better examples

Comments (0)

Files changed (1)

pa/test/test_readme.ml

 type t = 
-  | Foo of int list 
+  | Foo of u list 
   | Bar of int * int
+
+and u = { l : s list }
+
+and s = t list
 with ovisit
 
 class c = object
 
 let () = 
   let o1 = new c in
-  o1#t (Foo [1;2;3;4;5]);
-  assert (o1#st = 15);
+  o1#t (Foo [{l = [[ Bar (1,2); Bar (3,4) ]]}]);
+  assert (o1#st = 10);
   let o2 = new c in
   o2#t (Bar (1,2)); 
   assert (o2#st = 3)
 
-type u = { t : t; children : u list } with ovisit
+type v = { t : t; children : v list } with ovisit
 
-class c_u = object
+class c_v = object
   inherit c
-  inherit ovisit_u
+  inherit ovisit_v
 end
 
 let () = 
-  let o1 = new c_u in
-  o1#u { t = Foo [1;2;3;4;5]; children = [] }; 
-  assert (o1#st = 15);
-  let o2 = new c_u in
-  o2#u { t = Bar (1,2); 
-         children = [ { t = Foo [1;2;3;4;5]; children = [] };
+  let o1 = new c_v in
+  o1#v { t = Foo [{l = [[ Bar (1,2); Bar (3,4) ]]}]; children = [] }; 
+  assert (o1#st = 10);
+  let o2 = new c_v in
+  o2#v { t = Bar (1,2); 
+         children = [ { t = Foo [{l = [[ Bar (1,2); Bar (3,4) ]]}]; children = [] };
                       { t = Bar (3,4); children = [] } ]
        };
-  assert (o2#st = 25)
+  assert (o2#st = 17)
 
 module Fold = struct
 
   type t = 
-    | Foo of int list 
+    | Foo of u list 
     | Bar of int * int
+
+  and u = { l : s list }
+
+  and s = t list
   with ofold
 
   class c = object
 
   let () = 
     let o = new c in (* folder is pure, so we only need one o *)
-    assert ( o#t 0 (Foo [1;2;3;4;5]) = 15 );
+    assert ( o#t 0 (Foo [{l = [[ Bar (1,2); Bar (3,4) ]]}]) = 10 );
     assert ( o#t 0 (Bar (1,2)) = 3 ) 
 
 end
     | Foo of u list 
     | Bar of int * int
 
-  and u = { l : t list }
+  and u = { l : s list }
+
+  and s = t list
   with omap
 
   class c = object
 
   let () = 
     let o = new c in (* folder is pure, so we only need one o *)
-    assert ( o#t 0 (Foo [{l = [ Bar (1,2); Bar (3,4) ]}]) 
-             = (10, Foo [{l = [ Bar (2,3); Bar (4,5)]}]) );
+    assert ( o#t 0 (Foo [{l = [[ Bar (1,2); Bar (3,4) ]]}]) 
+             = (10, Foo [{l = [[ Bar (2,3); Bar (4,5) ]]}]) );
     assert ( o#t 0 (Bar (1,2)) = (3, Bar (2,3)) ) 
 
 end
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.