2012-11-14 56 views
3

这只是一个简单的程序,我写的是为了更好地理解模块。我试图用Id("a",Int)来调用toS函数,但是好像我可以写这样的ast类型。可能是什么问题?OCaml这个函数应用于太多的参数

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) 

回答

6

由于您没有在函数应用程序中将类型构造函数与parens包围在一起,因此出现错误。但是,您还必须在其定义的模块外部使用完全限定名称引用类型构造函数。

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

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

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

或ocaml的> = 3.12:__Ast(TOS(ID( “A”,Typ.Int)))__ – Kakadu

+0

谢谢!这解决了我的问题 – otchkcom