2012-11-14 58 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