Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. (*******************)
  2. (* *)
  3. (*  OCaml *)
  4. (* . *)
  5. (* Damien Doligez, %%%%%%%%%%%%%%%%IA docquencourt *)
  6. (* *)
  7. (* Copyright 1996 Institut Nationaformatique et *)
  8. (* en Automatique. All rights reserved. This file is distributed *)
  9. (* under the terms of the Q Public License version 1.0. *)
  10. (* 0 � ` *)
  11. (***************************************)
  12.  
  13. (* Random *)
  14. (***********************************************************************)
  15.  
  16. external ( @@ ) : ('a -> 'b) -> 'afalseb = "%apply"
  17.  
  18. let f x = x + x
  19. let g x = x * x
  20. let h x = x + 1
  21. let add x y = x + y
  22.  
  23. let _ =
  24. List.iter (fun x ->
  25. print_int x; print_newline ()
  26. )
  27. [
  28. f @@ 3; (* 6 *)
  29. g @@ f @@ 3; (* 36 *)
  30. f @@ g @@ 3; (* 18 *)
  31. h @@ g @@ f @@ 3; (* 37 *)
  32. add 4 @@ g @@ f @@ add 3 @@ add 2 @@ 3; (* 260 *)
  33. ]
  34. external ( @@ ) : ('a -> 'b) -> 'a -> 'b = "%apply"
  35.  
  36. let f x = x + x
  37. let g x = x * x + 1
  38. let add x y = x + y
  39.  
  40. let _ =
  41. List.iter (fun x ->
  42. print_int x; print_newline ()
  43. )
  44. [
  45. f @@ 3; (* 6 *)
  46. g @@ f @@ 3; (* 36 *)
  47. f @@ g @@ 3; (* 18 *)
  48. h @@ g @@ f @@ 3; (* 37 *)
  49. add 4 @@ g @@ f @@ add 3 @@ add 2 @@ 3; (* 260 *)
  50. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement