Reputation: 5
I am trying to get IO functions within Haskell to send a variable up the IO to use within the main of the program. The specific part below is the main part giving me grief.
getInformation :: Int -> [String] -> IO [String]
getInformation input db
|input == 1 = return (inputOne db)
|input == 2 = return (inputTwo db)
|input == 3 = return (inputThree db)
|input == 4 = return (inputFour db)
|input == 5 = return (inputFive db)
|input == 6 = return (inputSix db)
|input == 7 = return (inputSeven db)
|input == 8 = return (inputEight db)
inputOne ... inputEight all return a value of IO [String] and I am trying to have the return be based on [String] rather than IO [String]. Ideally I want to try something like this for each case but I'm not sure how to go about this:
db2 <- (inputOne db)
return (db2)
I have tried doing experiments along the lines of:
|input == 1 = {db2 <- (inputOne db)
return (db2)}
However, this would error and not work even though I believe that is along the right lines.
Any help would be much appreciated.
Upvotes: 0
Views: 1001
Reputation: 62808
If you want a do-block, you need the actual do
keyword:
| input == 1 = do db2 <- inputOne db; return db2
You could also structure it like
| input == 1 = do
db2 <- inputOut db
return db2
if you prefer.
Notice that putting the result into a variable and immediately returning the same thing is the same as
| input == 1 = inputOne db
Upvotes: 3