简化函数返回模块

Simplify function returning module

这个功能应该可以精简,去掉不必要的let module T = ...。但是怎么办?!我不断收到语法错误。提示?

let make_module dice_results : (module Tellstory.T) =
  let dice_calls = ref 0 in (* nr of times dice has been called *)
  let module T = Tellstory.Make(struct
    let dice n = 
      let result = List.nth dice_results (!dice_calls) in
      dice_calls := !dice_calls + 1;
      result
  end) in
  (module T)

我无法检查你的模块,但这是一个灵感示例:

let make_module () : (module Unit) =
  (module Comparable.Make (struct type t = int with compare, sexp end))

看起来像下面这样,应该可以工作:

let make_module dice_results : (module Tellstory.T) =
  let dice_calls = ref 0 in (* nr of times dice has been called *)
  (module Tellstory.Make(struct
    let dice n = 
      let result = List.nth dice_results (!dice_calls) in
      dice_calls := !dice_calls + 1;
      result
  end))