我正在尝试从文件中获取一些数据,然后对其进行解析并将其作为参数传递给另一个函数。
data LogLine = LogLine {
name :: String
, args1 :: String
, args2 :: String
, constant :: String
} deriving (Ord, Show, Eq)
main = do
file <- readFile "foo"
let result = (parse final "Input" file) --Parses the file into the LogLine datatype
let firstargs = getFirstArgs result --Get the first argument out of the datatype
let secondargs = getSecondArgs result --Get the second argument out of the datatype
let constant = getConstant result --Get the constant out of the datatype
createGraph firstargs secondargs constant --THIS IS THE PROBLEM
问题是,每当我尝试读入一个文件时,它就会变成一个(IO 字符串),无论我做什么,我都必须携带 IO。该createGraph
函数被声明为
createGraph :: String -> String -> String -> Argument
但是每当我尝试执行最后一条语句时,它都会抱怨:
Couldn't match expected type `IO a0' with actual type `Argument'
In the return type of a call of `createGraph'
我不允许更改createGraph
函数的返回类型,因为它是我需要向其提供参数的大型框架的一部分。有哪些处理方法?