fork download
  1.  
  2. module Pair :
  3. sig
  4. type t
  5. val of_int : int -> t
  6. val ( = ) : t -> t -> bool
  7. end
  8. =
  9. struct
  10.  
  11. type t = { x : int ; y : int }
  12.  
  13. let of_int i = { x = i ; y = i }
  14.  
  15. let ( = ) a b =
  16. a.x = b.x && a.y = b.y
  17.  
  18. end
  19.  
  20. module Ext = struct
  21.  
  22. module Pair =
  23. struct
  24. include Pair
  25.  
  26. let ( <> ) a b =
  27. not (a = b)
  28.  
  29. end
  30.  
  31. end
  32.  
  33.  
  34.  
  35. let main_std () =
  36. let a = Pair.of_int 1
  37. and b = Pair.of_int 1
  38. and c = Pair.of_int 2 in
  39. Printf.printf "%B %B\n" (a = b) (a = c)
  40.  
  41. let main_ext () =
  42. let open Ext in
  43.  
  44. (* same part *)
  45. let a = Pair.of_int 1
  46. and b = Pair.of_int 1
  47. and c = Pair.of_int 2 in
  48. Printf.printf "%B %B\n" (a = b) (a = c)
  49. (* same part end *)
  50.  
  51. ; Printf.printf "%B %B\n" (a <> b) (a <> c)
  52.  
  53. let _ =
  54. main_std () ;
  55. main_ext ()
  56.  
  57.  
  58.  
  59. (* type compatibility *)
  60.  
  61. let std_pair x =
  62. Pair.of_int x
  63.  
  64. let ext_pair x =
  65. let open Ext in
  66. Pair.of_int x
  67.  
  68. let _ =
  69. let a = std_pair 1
  70. and b = ext_pair 1 in
  71. Printf.printf "%B\n" (a = b) (* compiled *)
  72.  
Success #stdin #stdout 0s 5500KB
stdin
Standard input is empty
stdout
true false
true false
false true
true