0
while :: Int -> Bool -> (Int,Int) -> (Int,Int) ->[Int] -> String
while arguments validity premRange atomRange operators = 
     return(if validity then "Hello" else "NO")



main :: IO()
main =
    do   
putStrLn "Welcome to Random Argument Generator"
arguments <- getArguments
validity <- getValidity
putStrLn "Enter the range of the number of premises to each argument"
premRange <- getRange
putStrLn "Enter the range of the number of atomic statments per premises"
atomRange <- getRange
operators <- getOperators
putStrLn "Thank You!\nExecuting..."
test <- while arguments validity premRange atomRange operators
putStrLn "Good Bye"

Its complaining about my return in while and my call to it. i made this function as a test and im really confused as to what its complaining about exactly.

4
  • 4
    return in Haskell does not mean what it means in other languages. For normal functions, you will never need to use return. Commented Mar 14, 2013 at 1:53
  • what about IO functions i used return in those and they worked but is that for some other reason Commented Mar 14, 2013 at 2:18
  • @user2150839, return in Haskell is specifically about IO (and other monads); namely it makes an IO computation out of a pure value. return :: a -> IO a Commented Mar 14, 2013 at 3:05
  • @user2150839: In a normal language returning a monad from a function would look like return IO("xxx"). In Haskell, the return statement is implicit, the monad constructor is called return and the "xxx"stays the same. Commented Mar 14, 2013 at 5:33

1 Answer 1

1

In Haskell an expression such as an if expression is a perfectly fine definition for a function. You can just remove the word return.

After that, you're going to have a problem in main where one line doesn't do I/O, so its type isn't compatible with the surrounding do (I think):

test <- while arguments validity premRange atomRange operators

But, aha, you can change it to:

let test = while arguments validity premRange atomRange operators
Sign up to request clarification or add additional context in comments.

4 Comments

hmm yes trying to figure out why aswell
Turns out that i need to make it an IO string which i dont exactly understand why and then keep the if statement as a return. i thought IO mainly was for outputting to a file or screen not assigning to something in a IO function
ooooooooo thats right <- only applies to IO only i remember now its all coming back now! thank you!
if you use let test = while ... you won't need to make the string an IO

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.