Function returning module created by functor

138 Views Asked by At

I have problems defining the type of a module that is returned by a functor. Could anyone solve this?

module type ANIMALTYPE = sig
  val age : unit -> int
end

module type SHIPGENERATOR = sig
  val age : unit -> int
  (* Another possibility: include ANIMALTYPE *)
  val hello : string
end

module RabbitModule : ANIMALTYPE = struct
  let age () = 10
end

module Make_ShipGenerator (A : ANIMALTYPE) = struct
  let age = A.age
  let hello = "world"
end

let get_shipgenerator race = match race with
  | Rabbit -> let module M = (Make_ShipGenerator (RabbitModule)) 
    in (module M : SHIPGENERATOR)

Edit: Added hello to Make_ShipGenerator.

Edit 2: Added module type SHIPGENERATOR, which will include those parts needed from ANIMALTYPE.

1

There are 1 best solutions below

5
On BEST ANSWER

Well, it is ANIMALTYPE, what else?

let module M = (Make_ShipGenerator (RabbitModule)) 
    in (module M : ANIMALTYPE);;