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?
Why would you want to do that?
The only way to get your value into the IO monad is by using return.
You can either wrap the call to createGraph into another function like
or just use another let binding and use your value when you need it.
I can’t figure out what you want to do there.Please give us more details as in what do you want to do with the returned value.
—
From what i understand from your comment you just need to return the argument so the only thing you have to do is return $ createGraph firstargs secondargs constant and rename the function from main to something else because main must have type IO ().