Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type 'a option=
- None
- | Some of 'a;;
- type maybeAnInt =
- NotAnInt
- | AnInt of int;;
- let quo x y = match x, y with
- _, AnInt 0-> NotAnInt
- | AnInt m, AnInt n -> AnInt (m/n)
- | _->NotAnInt;;
- type foo =Foo;;
- type boolean = F|T;;
- let conj a b = match a, b with
- F,_ -> F
- | _,F -> F
- | _->T;;
- let (&&&) = conj;;
- let verdadero = T;;
- let falso = F;;
- let conj b1 b2 = match b1, b2 with
- verdadero, verdadero ->verdadero
- | _->falso;;
- type t = T of int;;
- type tt = L of int | R of int;;
- type num = F of float | I of int;;
- type nat = Z | S of nat;;
- let rec suma x y = match x with
- Z -> y
- | S n -> suma n (S y);;
- let rec sum n1 = function
- Z-> n1
- |S n2-> sum (S n1) n2;;
- let rec nat_of_int = function
- 0->Z
- | n-> n < 0 then raise (Invalid_argument "nat_of_int")
- else S (nat_of_int(n-1));;
- let rec nat_of_int = function
- 0->Z
- | n->S (nat_of_int(n-1));;
- let nat_of_int n=
- if n<=0 then raise (Invalid_argument "nat_of_int")
- else nat_of_int n;;
- type 'a btree=
- E
- | N of 'a * 'a btree * 'a btree;;
- let l x = N (x, E, E);;
- let rec num_nodes = function
- E->0
- |N(_,lb,rb)-> 1 + num_nodes lb + num_nodes rb;;
- let rec height = function
- E->0
- | N(_,lb,rb)-> 1+ max(height lb) (height rb);;
- let rec preorder = function
- E->[]
- |N (x,lb,rb) -> (x:: preorder lb) @ (preorder rb);;
- let leaves = function
- E-> []
- | N (r,E,E) -> [r]
- | N (_,l,r) -> leaves l @ leaves r;;
- type 'a st_tree =
- Leaf of 'a
- | Node of 'a * 'a st_tree * 'a st_tree
- let rec mirror = function
- Leaf v -> Leaf v
- | Node (v,l,r)-> Node (v,mirror r, mirror l);;
- type 'a gtree =
- GT of 'a * 'a gtree list;;
- let rec nngt (GT (_,l))=
- GT (_,l)-> List.fold_left (+) 1 List.map nngt l;;
- let rec nngt = function
- GT(_,[])->1
- | GT(v,h::t) -> nngt h + nngt (GT (v,t));;
- let rec b_of_st = function
- Leaf v->N(v,E,E)
- | Node (v,l,r) -> N(v,b_of_st l, b_of_st r);;
- let rec st_of_b = function
- E-> raise (Failure "st_of_b")
- | N(v,E,E)-> leaf v
- | N(v,l,r)-> Node (v, st_of_b l, st_of_b r);;
- let root = function
- E -> raise (Failure "root")
- | N (r,_,_)->r;;
Add Comment
Please, Sign In to add comment