Lst.map;; "hello world";; "hello" ^ "world";; let h = "hello";; h.[0];; type t = char list;; ['a';'b';'c'];; [1;2;3];; let rec sum n = if n <= 0 then 0 else n + sum (n-1);; sum 3;; #trace sum;; sum 3;; #trace Lst.replicate;; Lst.replicate 3 'c';; let toplevel_printer fmt s = Format.fprintf fmt "\"%s\"" (String.escaped(to_string s)) ;; open Strng;; let toplevel_printer fmt s = Format.fprintf fmt "\"%s\"" (String.escaped(to_string s)) ;; ['a';'c'];; #uninstall Strng.toplevel_printer;; #uninstall_printer Strng.toplevel_printer;; #remove_printer Strng.toplevel_printer;; ['a';'c'];; #install_printer Strng.toplevel_printer;; ['a';'c'];; let p = (7,3,"*******";" hello ";"*******");; let p = (7,3,["*******";" hello ";"*******"]);; Picture.p;; p;; #remove_printer Picture.toplevel_printer;; p;; #remove_printer Strng.toplevel_printer;; p;; #install_printer Strng.toplevel_printer;; #install_printer Picture.toplevel_printer;; p;; let p1 = (5,1,of_string "hello");; open Strng;; let p1 = (5,1,of_string "hello");; let p2 = (5,1,of_string "world");; Picture.above p1 p2;; let p2 = (5,1,[of_string "world"]);; let p1 = (5,1,[of_string "hello"]);; Picture.above p1 p2;; Lst.foldr;; Lst.foldr (+) 0 [1;2;3];; Lst.foldr (Picture.above) 0 ps;; let stack ps = Lst.foldr1 (Picture.above) ps;; stack [p1;p1;p2;p2];; (* useless foldr1 function since base case is missing *) let rec foldr1 f = function | [] -> failwith "foldr1.empty" | x::xs -> f x (foldr1 f xs);; foldr1 (+) [];; foldr1 (+) [1;2;3];; let rec foldr1 f = function | [] -> failwith "foldr1.empty" | [x] -> x | x::xs -> f x (foldr1 f xs);; let rec zip_with f xs ys = match (xs,ys) with | ([],_) | (_,[]) -> [] | (x::xs,y::ys) -> f x y::zip_with f xs ys;; zip_with ( * ) [1;2] [3;4;5];; zip_with ( * ) [] [];; let h = pixel 'h';; open Picture;; let h = pixel 'h';; let e = pixel 'e';; beside h e;; let row s = spread(Lst.map pixel s);; row ['h';'e';'l';'l';'o'];; row [1;2;3];; empty 3 3;; #remove_printer Picture.toplevel_printer;; empty 3 3;; #install_printer Picture.toplevel_printer;; empty 3 3;; open Picture;; tile [[p00;p01;p02];[p10;p11;p12]];; tile_with 1 1 [[p00;p01;p02];[p10;p11;p12]];; let rec join d = function | [] -> [] | x::xs -> x@d@join d xs;; let test = tile_with 1 1 [[p00;p01;p02];[p10;p11;p12]];; to_strng test;; #remove_printer Strng.toplevel_printer;; to_strng test;; empty 0 3;; empty 1 0;; let empty w h = if w = 0 then (0,h,Lst.replicate h []) else if h = 0 then (w,0,[]) else empty w h (* rotate : t -> t *) let rotate (w,_,pss) = Lst.foldr (fun l p -> beside p (column l)) (empty 0 w) pss ;; test;; rotate test;;