Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*Zad1*)
- type 'a llist = LNil | LCons of 'a * (unit -> 'a llist);;
- let lengthll ll =
- let rec licz (l,acc) =
- match l with
- | LCons(x,xf) -> licz (xf(),acc+1)
- | LNil -> acc
- in licz(ll,0);;
- let cut (ll,p,k)=
- let rec licz (l,n,acc) =
- match l with
- | LCons(x,xf) ->
- if n>0 then licz(xf(),n-1,acc)
- else licz(xf(),n-1,LCons(x,function() -> acc))
- | LNil -> acc
- in licz(licz(ll,p,LNil),k,LNil);;
- let rec ltake = function
- (0,xq) -> []
- | (n, LNil) -> []
- | (n, LCons(x,xf)) -> x::ltake(n-1,xf());;
- let leniwa = LCons(1,
- function()-> LCons(2,
- function()-> LCons(3,
- function()-> LCons(4,
- function()-> LCons(5,
- function()-> LNil)
- ))));;
- ltake(10, cut(leniwa,0,0));;
- (*Zad2*)
- type ('a, 'b) slowa = Wyraz of 'a * 'b;;
- let insert (slownik,slowo) =
- let rec ins snk =
- match snk with
- | h::t ->
- let Wyraz(swo,wyst) = h in
- if swo=slowo then Wyraz(swo,wyst+1)::t
- else if slowo<swo then Wyraz(slowo,1)::h::t
- else h::ins t
- | [] -> [Wyraz(slowo,1)]
- in ins slownik;;
- insert(insert(insert(insert(insert([],1),2),2),3),1);;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement