(***** session is starting -- Sun Jan 7 10:51:20 IST 2024 ****) \n\n;; let rec fib = fun n ->\n match n with\n | 0 -> 1\n | 1 -> 1\n | n -> (fib ( n - 1)) + (fib (n - 2));; fib 0;; fib 1;; fib 2;; fib 3;; fib 4;; fib 5;; fib 40;; fib 100;; let rec iter = fun n f x -> \n match n with\n | 0 -> x\n | n -> (f (iter (n - 1) f x));; let f = fun (x,y) -> (x+y,x);; let fib = fun n -> iter n f (1,1);; fib 0;; fib 1;; fib 3;; fib 2;; fib 3;; fib 4;; let fib = fun n -> (first (iter n f (1,1)));; let first = fun (x,y) -> x;; let fib = fun n -> (first (iter n f (1,1)));; fib 0;; fib 1;; fib 2;; fib 3;; fib 4;; fib 5;; let fib = fun n -> (second (iter n f (1,1)));; let second = fun (x,y) -> y;; let fib = fun n -> (second (iter n f (1,1)));; fib 5;; fib 0;; fib 1;; fib 2;; fib 3;; fib 4;; fib 5;; fib 40;; fib 100;; let fib = fun n -> (second (iter n f (1,1)));; let rec loop = fun p f x -> if (p x) then x else (loop p f ( f x));; 5;; fib 100;; let rec loop = fun p f x -> if (p x) then x else (loop p f ( f x));; let p = fun x -> x;; let f = fun x -> x > 0;; loop f x p;; loop f 0 p;; loop f p 0;; loop (fun x -> (x > 0)) (fun x -> x) 0;; loop (fun x -> false) (fun x -> x) 0;; loop (fun x -> false) (fun x -> (x+1)) 0;; type complex = {re_part: float, im_part: float};; type complex = {re_part: float; im_part: float};; let cx1 = {re_part = 1.0; im_part = 0.5};; cx1.re_part;; fun c1 c2 -> {re_part = c1.re_part + c2.re+part; im_part = c1.im_part + c2.im_part};; fun c1 c2 -> {re_part = c1.re_part +. c2.re+part; im_part = c1.im_part +. c2.im_part};; fun c1 c2 -> {re_part = c1.re_part +. c2.re_part; im_part = c1.im_part +. c2.im_part};; type point = {x: float; y: float};; type circle = {center: point; ratius: float};; type circle = {center: circle; ratius: float};; type circle1 = {center: circle1; ratius: float};; type color = Blue | Red | Green;; let x = Red;; type data = IntData of int | StringData of string | PairData of int*string;; IntData(3);; let x = IntData(3);; let x = PairData();; let x = PairData((5,"a"));; type data = IntData of int | StringData of string | PairData of int*string;; let typeof = fun d -> match d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData((p1,p2)) -> "pair";; typeof(IntData(5));; type inttree = Leaf of int | Node of inttree * inttree;; Leaf(5);; Node(Leaf 3, Node (Leaf 4) (Leaf 5));; Node(Leaf 3, Node ((Leaf 4), (Leaf 5)));; let rec sum = fun t -> match t with\n | Leaf(x) -> x\n | Node(n1,n2) -> (sum n1) + (sum n2);; let t = Node(Leaf 3, Node ((Leaf 4), (Leaf 5)));; t;; sum t;; type exp = Constant of int \n | Variable of string\n | Addition of exp*exp\n | Multiplication of exp*xp;; type exp = Constant of int \n | Variable of string\n | Addition of exp*exp\n | Multiplication of exp*exp;; ; a;; # a;; (* aa *);; (* x + 3 *);; Addition(Variable("x"), Constant(3));; type 'a tree = Leaf of 'a | Node of ('a tree) * ('a tree);; Node(Leaf(3), Node(Leaf 4, Leaf 5));; Node(Leaf("3"), Node(Leaf "4", Leaf "5"));; Leaf(IntData(3));; type 'a tree = Leaf of 'a | Node of ('a tree) * ('a tree);; Leaf(3);; Leaf(3: int);; type 'a linkedlist = Nil | Cons of 'a * ('a linkedlist);; Nil;; Cons(3, Nil);; [];; 3::[];; 3::4::5;; 3::4::5::Nil;; 3::4::5::[];; Cons(3, Cons(4, Cons(5, Nil)));; [1;2;3];; type point = {x: float; y: float};; type point = {x: point; y: float};; (***** session is starting -- Sun Jan 7 12:32:54 IST 2024 ****) type point = {x: point; y: float};; let a = {x=a; y=1.0};; let rec a = {x=a; y=1.0};; a;; let rec len = fun l -> match l with\n | Nil -> 0\n | Cons(e,ll) -> 1 + (len ll);; type 'a linkedlist = Nil | Cons of 'a * ('a linkedlist);; let rec len = fun l -> match l with\n | Nil -> 0\n | Cons(e,ll) -> 1 + (len ll);; len [];; len Nil;; len Cons(1,Cons(5, Nil));; let rec len = fun l -> match l with\n | Nil -> 0\n | Cons(e,ll) -> 1 + (len ll);; len Cons(1, Cons(5, Nil));; let rec len = fun l -> match l with\n | Nil -> 0\n | Cons(e,ll) -> 1 + (len ll);; len Cons(1,Nil);; len Cons((1,Nil));; (len Cons((1,Nil)));; let rec length = fun l -> match l with\n | Nil -> 0\n | Cons(e,ll) -> 1 + (length ll);; (length Cons((1,Nil)));; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1 + len(t);; len [];; len [1;2;3];; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1 + len(t);; let rec map = fun l f -> \n match l with\n | [] -> []\n | h::t -> f(h)::(map t f);; map [1;2;3] (fun x -> x*x);; type data = IntData of int | StringData of string | PairData of int*string;; fun x -> match x with IntData(3) -> x | x;; let rec append = fun l r -> match l with \n | [] -> r\n | h::t -> h:: (append t r);; append [1;2;3] [10;20;30];; let rec fold_left = fun f accu l -> \n match l with\n | [] -> accu\n | h::t -> fold_left f (f accu a) l;; let rec fold_left = fun f accu l -> \n match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1 + len(t);; let rec fold_left = fun f accu l -> \n match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let len = fun l -> fold_left (fun x y -> x + 1) 0 l;; type data = IntData of int | StringData of string | PairData of int*string;; let f = fun x -> match x with\n | IntData 3 -> Intdata 3\n | _ -> 5;; let f = fun x -> match x with\n | IntData 3 -> IntData 3\n | _ -> IntData 5;; f IntData 1;; f (IntData 1);; f (IntData 3);; f (IntData 2);; f (IntData 4);; let x=5 in x*x;; let rec f = fun x -> x*x in (f 5);; (f 5);; let rec fib = fun n -> match n with\n | 0 -> 1\n | 1 -> 1\n | n -> fib(n-1) + fib(n-2);; fib 0 ;; fib 1 ;; fib 2 ;; fib 3 ;; fib 4 ;; fib 5 ;; fib 40 ;; fib 100 ;; let rec fib = fun n -> match n with\n | 0 -> 1\n | 1 -> 1\n | n -> fib(n-1) + fib(n-2);; let rec iter = fun n f x -> match n with\n | 0 -> x\n | n -> (f (iter (n-1) f x));; let fib = fun n -> iter n f (1,1);; let f = fun (x,y) -> (x+y,x);; let fib = fun n -> iter n f (1,1);; fib 5;; let first = fun (x,y) -> x;; let fib = fun n -> first (iter n f (1,1));; fib 5;; fib 0;; fib 1;; fib 2;; fib 3;; let fib = fun n -> second (iter n f (1,1));; let second = fun (x,y) -> y;; let fib = fun n -> second (iter n f (1,1));; fib 0;; fib 2;; fib 1;; fib 2;; fib 3;; fib 4;; fib 5;; fib 40\n;; fib 100;; let fib = fun n -> second (iter n f (1,1));; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; 5;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; let p = _ -> false;; let p = x -> false;; let p = fun(x) -> false;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; loop 2;; loop (p f x);; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; loop (fun x -> false) (fun x -> x) 1;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; loop (fun x -> false) (fun x -> x) 1;; type complex = {re_part: float; im_part: float};; let cx1 = {re_part = 1.0; im_part = 0.5};; cx1.re_part;; fun c1 c2 -> {re_part = c1.re_part +. c2.re_part; im_part = c1.im_part +. c2.im_part };; (fun c1 c2 -> {re_part = c1.re_part +. c2.re_part; im_part = c1.im_part +. c2.im_part })cx1 cx1;; let p = fun c1 c2 -> {re_part = c1.re_part +. c2.re_part; im_part = c1.im_part +. c2.im_part };; type point = {x: float; y:float};; type circle = {center: point; radius: float};; type color = Blue | Red | Green;; 5;; Blue;; type data = IntData of int | StringData of string | PairData of int*string;; let d = IntData(5);; let d = StringData("hey");; type data = IntData of int | StringData of string | PairData of int*string;; let typeof = fun d -> d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p) -> "pair";; let typeof = fun d -> match d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p) -> "pair";; let typeof = fun d -> match d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData p -> "pair";; let typeof = fun d -> match d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData _ -> "pair";; data;; type data = IntData of int | StringData of string | PairData of int*string;; typeof IntData(5);; let typeof = fun d -> match d with\n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData _ -> "pair";; typeof IntData(5);; typeof(IntData(5));; type inttree = Leaf of int | Node of inttree * inttree;; Node(Leaf 3, Node (Leaf 4) (Leaf 5));; Node(Leaf 3, Node (Leaf 4,Leaf 5));; let rec sum = fun t -> match t with \n | Leaf(n) -> n\n | Node(t1, t2) -> (sum t1) + (sum t2);; sum(Node(Leaf 3, Node (Leaf 4,Leaf 5));;) sum(Node(Leaf 3, Node (Leaf 4,Leaf 5)));; type inttree = Leaf of int | Node of inttree * inttree;; let rec sum = fun t -> match t with \n | Leaf(n) -> n\n | Node(t1, t2) -> (sum t1) + (sum t2);; type inttree = Leaf of int | Node of inttree * inttree;; type 'a tree = Leaf of 'a | Node of ('a tree)*(' a tree);; Node(Leaf 3, Node (Leaf 4,Leaf 5));; Node(Leaf "3", Node (Leaf "4",Leaf "5"));; type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree;; type tree = Leaf of 'a | Node of 'a tree * 'a tree;; type 'a list = Nil | Cons of 'a * ('a list);; Nil;; Cons(5, Nil);; Cons(5, Cons(6, Nil));; type 'a list = Nil | Cons of 'a * ('a list);; Cons(5, Cons(6, Nil));; [];; (***** session is starting -- Sun Jan 7 15:19:35 IST 2024 ****) [];; 5::[];; [1;2;3];; ::(1,[]);; [1;2;3];; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1+ (len t);; len [1;2;3;4];; len [];; len [1];; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1+ (len t);; let rec map = fun l f -> match l with\n | [] -> []\n | h::t -> (f h)::(map t f);; fun l -> map l (fun x -> x*x);; let sq = fun l -> map l (fun x -> x*x);; sq [1;2;3;4];; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu a) t;; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let len = fun l -> fold_left ( x y -> x + 1) 0 l;; let len = fun l -> fold_left (fun x y -> x + 1) 0 l;; len [];; len [1];; len [1,4,5,6];; len [1;4;5;6];; let len = fun l -> fold_left (fun x y -> x + 1) 0 l;; ::;; type 'a list = Nil | Cons of 'a * ('a list);; Cons;; type 'a list = Nil | Cons of 'a * ('a list);; let rec append = fun l r -> match l with \n | [] -> r\n | h::t -> h:: (append t r);; (***** session is starting -- Sun Jan 7 15:56:39 IST 2024 ****) let rec append = fun l r -> match l with \n | [] -> r\n | h::t -> h:: (append t r);;