Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type 'a nlist = Koniec | Element of 'a * ('a nlist);;
- let rec podziel nlista =
- match nlista with
- | Element(h,t) -> let (lista1, lista2) = podziel t in if h mod 2 <> 0 then (dolacz lista1 h, lista2) else (lista1, dolacz lista2 h)
- | Koniec -> (Koniec,Koniec);;
- let rec dolacz nlista x =
- Element(x,nlista);;
- let nlist = Element(5, Element(6,Element(3, Element(2, Element(1,Koniec)))));;
- podziel nlist;;
- type 'a llist = LKoniec | LElement of 'a * (unit -> 'a llist);;
- let ltl = function
- |LKoniec -> failwith "ltl"
- | LElement (_, xf) -> xf();;
- let rec ltake = function
- |(0, _) -> []
- | (_, LKoniec) -> []
- | (n, LElement(x,xf)) -> x::ltake(n-1, xf());;
- let rec toLazyList = function
- |[] -> LKoniec
- | h::t -> LElement(h, function () -> toLazyList t);;
- let rec (@$) ll1 ll2 =
- match ll1 with
- |LKoniec -> ll2
- | LElement(x, xf) -> LElement(x, function () -> (xf()) @$ ll2);;
- let rec dolacz llista x =
- let ll1 = LElement(x,function ()->LKoniec) in ll1 @$ llista ;;
- let rec lpodziel llista =
- match llista with
- | LElement (x,xf) ->let (lista1, lista2) = lpodziel (ltl llista) in if x mod 2 <> 0 then (dolacz lista1 x, lista2) else (lista1, dolacz lista2 x)
- | LKoniec -> (LKoniec, LKoniec);;
- let l1 =toLazyList[5;6;3;2;1];;
- let l2 = lpodziel l1;;
- let convert llisty=
- match llisty with
- | (LKoniec, LKoniec) ->([],[])
- | (LElement(x,xf),LKoniec) -> (x::ltake(5,xf()),[])
- | (LKoniec, LElement(x,xf)) -> ([],x::ltake(5,xf()))
- | (LElement(x1,xf1),LElement(x2,xf2))-> (x1::ltake(5,xf1()),x2::ltake(5,xf2()));;
- convert l2;;
Add Comment
Please, Sign In to add comment