2017-09-04 34 views
0

如果我有一个包含(.re)文件如何在接口文件中使用函数的输出签名?

module IntMap = 
    Map.Make { 
    type t = int; 
    let compare = compare; 
    }; 

type foo = IntMap.t string; 

哪能的foo签名添加到接口的实现(.rei)文件?在与OCaml中的

module IntMap = Map.S with type key = int 
type foo = string IntMap.t 

我预想的比喻它是

module IntMap = 
    Map.S { 
    type t = int; 
    }; 

type foo = IntMap.t string; 

但在{导致语法错误。

回答

1

我怀疑问题的根本原因是您发布的OCaml代码无效。它应该是

module IntMap: Map.S with type key = int 

那么原因是等价

module IntMap: Map.S with type key = int; 
type foo = IntMap.t string; 

差别不大:)

此外,如果你没有意识到这一点,reason-tools是一个伟大的工具,将在Reason和OCaml之间转换。它确实需要有效的输入;)

+0

啊,谢谢。我的错误是1)引用OCaml的[无效示例](https://stackoverflow.com/review/suggested-edits/17241690)和2)试图[通过尝试原因转换](https://reasonml.github .io/try /?ocaml = LYewJgrgNgpgBASQHYBcCyBDADgLjprAOgGU4B3ASxQAs4UBPLeAaxnrgF44LUg),其在校正的OCaml中报告语法错误。 –

相关问题