Hello,
is there way to fix the following code:
module type CmdIface = sig
type message
val cmd : message -> unit
end
module type NetIface = sig
type init
val net : init -> init
end
module Cmd = struct
type message = int
let cmd v = v+1
end
module Net = struct
type init = { cvt: (module CmdIface) }
let net init =
let cvt = init.cvt in
let module R = (val cvt: CmdIface) in
R.cmd 1 (* line 22 with error *)
end
let i = { Net.cvt = (module Cmd: CmdIface) }
Net.net i
I got error:
File "
t.ml", line 22, characters 22-23:
Error: This expression has type int but an expression was expected of type
R.message
In case I do not use types in function signature code works well:
module type I = sig val f : int -> int end;;
module M = struct
let f v = v+1
end;;
type t = {cvt: (module M); v: int};;
let module R = (val i.cvt: I) in R.f i.v;;
- : int = 1
WBR, ssp