Module OCaml此函数应用于太多参数
这只是我写的一个简单的程序,试图更好地理解模块。我试图用Module OCaml此函数应用于太多参数,module,ocaml,Module,Ocaml,这只是我写的一个简单的程序,试图更好地理解模块。我试图用Id(“a”,Int)调用toS函数,但似乎我可以编写这样的ast类型。有什么问题吗 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
Id(“a”,Int)
调用toS
函数,但似乎我可以编写这样的ast类型。有什么问题吗
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)
您将收到一个错误,因为您没有在函数应用程序中使用paren包围类型构造函数。但是,您还必须在定义类型构造函数的模块之外使用完全限定名引用类型构造函数。即
Ast.toS (Ast.Id("a",Typ.Int))
或者,您可以打开模块。但这被认为是不好的做法。即
open Id
open Typ
Ast.toS (Id("a",Int))
或者使用ocaml>=3.12:Ast(toS(Id(“a”,Typ.Int)))