Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Printf
- let print_list cf l =
- let rec string_of_list l =
- match l with
- [] -> ""
- | h::tail -> cf h^";"^string_of_list tail
- in Printf.printf "[%s]\n" (string_of_list l);;
- print_list string_of_int [1;2;3;];;
- print_list string_of_int [1;2;3;];;
- print_list (fun x -> "\""^x^"\"") ["ala";"kot"];;
- (1,"ala",10.);;
- type foo =
- Nic
- | Liczba of int
- | Para of float * string
- | Tekst of string;;
- let x : foo = Para(3.,"ala");;
- let y = Nic;;
- let z = Tekst " i kot";;
- let f = function
- Nic -> 0
- | Liczba i -> i
- | Para (x,y) -> int_of_float x
- | Tekst s -> printf "%s\n" s; 1;;
- type 'a btree =
- Leaf of 'a
- | Node of 'a btree * 'a btree ;;
- Leaf 1;;
- (*
- let dab = Node ( Node(Leaf 1, Leaf 2),
- Leaf 3);;
- *)
- let list = Leaf 10;;
- let sosna = Node ( Node(Leaf "a", Leaf "ab"),
- Leaf "c");;
- let print_list cf l =
- let rec string_of_list l =
- match l with
- [] -> ""
- | h::tail -> cf h^";"^string_of_list tail
- in Printf.printf "[%s]\n" (string_of_list l);;
- print_list string_of_int [1;2;3;];;
- let print_tree cf d : 'a btree =
- let rec string_of_tree d =
- match d with
- Leaf f -> (cf f)
- | Node (n1,n2) -> " N("^string_of_tree n1^";"^string_of_tree n2^") "
- in printf "TREE -> [%s]\n" (string_of_tree d); d;;
- print_tree (fun x -> "'"^x^"'") sosna;;
- let dab = Node ( Node(Leaf 2, Leaf 1),
- Leaf 3);;
- print_tree string_of_int dab;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement