简化功能返回模块

时间:2015-04-10 21:14:43

标签: ocaml

此功能应该能够简化,删除不必要的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)

1 个答案:

答案 0 :(得分:0)

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

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))