OCaml此函数适用于太多参数

时间:2012-11-14 20:20:07

标签: module ocaml

这只是我编写的一个简单程序,试图更好地理解模块。我试图用toS调用Id("a",Int)函数,但似乎我可以像这样写一个类型。可能是什么问题?

module Typ =
struct
  type typ = Int | Bool
end

module Symbol =
struct
  type t = string
end

module Ast =
struct
  type ast = Const of int * Typ.typ | Id of Symbol.t * Typ.typ
  let rec toS ast = match ast with Id(a,b) -> "a"
    |_->"b"
end


Ast.toS Id("a",Int)

1 个答案:

答案 0 :(得分:6)

您收到错误,因为您没有在函数应用程序中使用parens包围您的类型构造函数。但是,您还必须通过它们所定义的模块之外的完全限定名称来引用类型构造函数。即。

Ast.toS (Ast.Id("a",Typ.Int))

或者,您可以打开模块。但这被认为是不好的做法。即。

open Id
open Typ
Ast.toS (Id("a",Int))