我正在尝试将带有文件名的wheatear参数传递给解析文件或从标准输入读取:
let formulae = fmap parseInput $ if isInputFile args then (hGetContents $ openFile (last args) ReadMode) else hGetContents stdin
但当然会发生以下错误:
formula-2-bdd.hs:89:79:
Couldn't match expected type `Handle' with actual type `IO Handle'
In the second argument of `($)', namely
`openFile (last args) ReadMode'
In the expression: (hGetContents $ openFile (last args) ReadMode)
如果我先绑定IO Handle,我就不能根据`isInputFile args:
来决定handle <- openFile (last args) ReadMode
formulae = fmap parseInput $ if isInputFile args then hGetContents handle else hGetContents stdin