Guest User

Untitled

a guest
Nov 16th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. type _ complist =
  2. One : ('a -> 'b) -> ('a * 'b) complist
  3. | Cons : ('a -> 'b) * ('b * 'c) complist -> ('a * 'c) complist
  4.  
  5. let rec clength : type a . a complist -> int = function
  6. | One _ -> 1
  7. | Cons (_, xs) -> 1 + clength xs
  8.  
  9. let rec ccompose : type a b . (a * b) complist -> (a -> b) = function
  10. | One f -> f
  11. | Cons (f, xs) -> (fun x -> ccompose xs (f x))
  12.  
  13. let (^:) a b = Cons (a, b)
  14.  
  15. let f1 (x : int) = x + 1
  16.  
  17. let f2 (x : int) = string_of_int x
  18.  
  19. let f3 (x : string) = "It's over " ^ x
  20.  
  21. let clist = f1 ^: f2 ^: One f3
  22.  
  23. let _ =
  24. print_int (clength clist);
  25. print_newline ();
  26. print_endline (ccompose clist 8999);;
Advertisement
Add Comment
Please, Sign In to add comment