I'm trying to get some data from a file, then parse it and pass it to another function as an argument.
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
The problem is that whenever I try to read-in a file it becomes an (IO String) and I always have to carry the IO whatever I do.
the createGraph function is declared as
createGraph :: String -> String -> String -> Argument
but whenever I try to execute the last statement it complains:
Couldn't match expected type `IO a0' with actual type `Argument'
In the return type of a call of `createGraph'
I'm not allowed to change the return type of the createGraph function, because it's a part of a large framework that I need to feed the arguments to.
What are the ways of dealing with this?
createGraphin your code and referencecreateArgumentin your description. Assuming they're the same function the problem is that the return type ofmainmust beIO ()but the return type ofcreateGraphisArgument.mainfunction in your code snippet the main for your program? If so then the final expression in the do block must have typeIO ()