code.ml
- open Batteries
- module type N = sig
- type t
- val make: unit -> t
- val add_to_self: t -> t -> unit
- val as_float: t -> float
- end
- module Int: N = struct
- type t = int ref
- let make () = ref 1
- let add_to_self x y = x := !x + !y
- let as_float = (!) |- float_of_int
- end
- module Float: N = struct
- type t = float ref
- let make () = ref 0.5
- let add_to_self x y = x := !x +. !y
- let as_float = (!) |- identity
- end
- let which_module = function
- | "float" -> (module Float: N)
- | "int" -> (module Int: N)
- | _ -> invalid_arg "which_module"
- let parse: string -> (module N with type t = 'a) * 'a = fun (type a) s ->
- let module C = (val (which_module s): N) in
- (module C: N), C.make ()
error.txt
- File "code.ml", line 30, characters 2-72:
- Error: This `let module' expression has type (module N) * C.t
- In this type, the locally bound module name C escapes its scope
- Command exited with code 2.