I've never used Haskell before and I'm struggling with the IO side of things. The code I'm writing, yes, is for a Uni assignment, and for that reason I'm not putting my whole code on here in case I get complained at for one of the many plagiarism clauses... so I'll keep it vague.
The function I'm struggling with doesn't need to call any other functions anyway so they're irrelevant, it just needs to do these things in order;
- start an IO loop to do the following;
- print a prompt (like "> ")
- read in a line, call it StrA
- check if StrA is empty, or equal to StrB (an argument), and if so end the loop
- repeat if the loop didn't end, i.e. the string's not empty and /= StrB
- finally print a final String*
*in my actual program, the final string that's printed would be returned from another function, but as it's not important I'll just say the String to be printed is "Finish".
So here's my attempt, hopefully (despite it being wrong) it'll give a clearer idea of what I'm trying to do:
func :: String -> IO()
func StrB =
do putStr "> "
StrA <- getLine
if (StrA == StrB || StrA == "") then return {- do you use return to end the loop?? idk -}
else func StrB
putStrLn "Finish"
The specification is for the function to be of type String -> IO() so that's the only thing that can't be changed I guess.
Thanks in advance if you can help, if I haven't explained myself well just lemme know!
Cheers,
Will