Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let headoflist lst = match lst with
- | [] -> failwith "Empty list"
- | [h] -> h
- | h :: t -> h
- let tailoflist lst = match lst with
- | [] -> failwith "Empty list"
- | [h] -> failwith "One element only"
- | h :: t -> t;;
- let rotate_left lst = match lst with
- | [] -> []
- | h :: t -> t @ [h];;
- let rec last = function
- | [] -> -1
- | [h] -> h
- | h :: t -> last t;;
- let rec maxoflist lst = match lst with
- | [] -> failwith "Empty list"
- | [h] -> h
- | h :: t -> max h (maxoflist t);;
- let u x y = x + y;;
- let f x y = 2 * x + y;;
- let rec apply f ac lst = match lst with
- | [] -> 0
- | [h] -> (f h ac)
- | h :: t -> (f h (apply f ac t));;
- type nrcomplex = Real of float | Complex of (float * float);;
- let add_complex x y = match (x, y) with
- | (Real x, Real y) -> Real(x +. y)
- | (Real x, Complex(ax, ay)) -> Complex(x +. ax, ay)
- | (Complex(ax, ay), Real y) -> Complex(ax, y +. ay)
- | (Complex(ax, ay), Complex(bx, by)) -> Complex(ax +. bx, ay +. by);;
- let mul_complex x y = match (x, y) with
- | (Real x, Real y) -> Real(x *. y)
- | (Real x, Complex(ax, ay)) -> Complex(x *. ax, x *. ay)
- | (Complex(ax, ay), Real y) -> Complex(y *. ax, y *. ay)
- | (Complex(ax, ay), Complex(bx, by)) -> Complex((ax *. bx -. ay *. by), (ax *. by +. bx *. ay));;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement