2017-04-25 24 views
-1

我想從我在SML中編寫的python文件調用函數。我收到tycon不匹配錯誤,我不明白爲什麼。這是我的SML碼在SML中調用Python函數

fun interpreter(inFile: string, outFile: string)= 
let 
    val s = interpreter(inFile, outFile) 
in 
    OS.Process.system ("python interpreter.py"^s) 
end; 

這是我收到

- use "in.sml"; 
[opening in.sml] 
in.sml:1.6-6.6 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch] 
    expression: ?.OS_Process.status 
    result type: string 
    in declaration: 
    interpreter = 
     (fn (<pat> : string,<pat> : string) => 
      let val <binding> in OS.Process.system <exp> end) 
val it =() : unit 

這是蟒蛇的方法錯誤我試圖撥打:

def interpreter(input, output): 
    x = Interpreter() 
    x.interpreter(input, output) 
+3

複製[在SML程序中調用Python文件?](http://stackoverflow.com/questions/43353918/call-a-python-file-in-a-sml-program)。請問你的問題一次。 –

+0

請使用縮進來格式化代碼塊,而不是反引號。如果您選擇文本並按下「{}」按鈕,它通常會做正確的事情。 – molbdnilo

+0

這將永遠不會終止,因爲評估取決於它自己的結果。 – molbdnilo

回答

2

編譯器試圖調和你在這裏遞歸調用的interpreter的結果/返回類型:val s = interpreter(inFile, outFile)。編譯器認爲s必須是string,因爲您將它與^連接起來,但函數的主體返回了由OS.Process.system ("python interpreter.py"^s)返回的值,它必須是?.OS_Process.status

+0

好吧,那麼我將如何去使用從SML函數接收的參數來調用python中的函數呢?我只是擺脫了串聯,所以它的'OS.Process.system(「python interpreter.py」)'?這允許sml程序編譯並返回這個'val解釋器= fn:string * string - > Word32.word val it =():unit'我的python程序應該輸出一個文本文件,Word32.word也是如此輸出我應該期待? – arizq29