Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type _ complist =
- One : ('a -> 'b) -> ('a * 'b) complist
- | Cons : ('a -> 'b) * ('b * 'c) complist -> ('a * 'c) complist
- let rec clength : type a . a complist -> int = function
- | One _ -> 1
- | Cons (_, xs) -> 1 + clength xs
- let rec ccompose : type a b . (a * b) complist -> (a -> b) = function
- | One f -> f
- | Cons (f, xs) -> (fun x -> ccompose xs (f x))
- let f1 (x : int) = x + 1
- let f2 (x : int) = string_of_int x
- let f3 (x : string) = "It's over " ^ x
- let clist = Cons (f1, Cons (f2, One f3))
- let _ =
- print_int (clength clist);
- print_newline ();
- print_endline (ccompose clist 8999);;
- (* prints
- 3
- It's over 9000 *)
Advertisement
Add Comment
Please, Sign In to add comment