spacepaste

code.ml

  1.  
  2. open Batteries
  3. module type N = sig
  4. type t
  5. val make: unit -> t
  6. val add_to_self: t -> t -> unit
  7. val as_float: t -> float
  8. end
  9. module Int: N = struct
  10. type t = int ref
  11. let make () = ref 1
  12. let add_to_self x y = x := !x + !y
  13. let as_float = (!) |- float_of_int
  14. end
  15. module Float: N = struct
  16. type t = float ref
  17. let make () = ref 0.5
  18. let add_to_self x y = x := !x +. !y
  19. let as_float = (!) |- identity
  20. end
  21. let which_module = function
  22. | "float" -> (module Float: N)
  23. | "int" -> (module Int: N)
  24. | _ -> invalid_arg "which_module"
  25. let parse: string -> (module N with type t = 'a) * 'a = fun (type a) s ->
  26. let module C = (val (which_module s): N) in
  27. (module C: N), C.make ()
  28.  

error.txt

  1.  
  2. File "code.ml", line 30, characters 2-72:
  3. Error: This `let module' expression has type (module N) * C.t
  4. In this type, the locally bound module name C escapes its scope
  5. Command exited with code 2.
  6.