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

You basically don't understand what's going on or how Haskell works and you need to go back to relearn some of the basics. This is going to take some time, since there's stuff that comes before do blocks, like mandatory variable naming conventions, that you should not be confused with, and yet you are. There's not much of a point of filling these informational blanks -- it's too much. Go back and learn the material you should have learned already.

Thanks for the great help.
It's irrelevant anyway the assignment I was asking for at the time was in over a week ago.
I understand how to do it now, and I got it right in time, but for the record we'd only had like 4 hours of lectures learning the language! And when you're given a week to do an assignment it's hard to go through books and learn the language in time, that's why I was asking for help. Hell it's hard to find a book on Haskell in our Library in the space of a week.

I would recommend checking out Learn You a Haskell online. It's a tutorial, and it's well-written and focused. It will be useful. Maybe you're already past the point where it would be useful. Anyway, I'm glad you got through the assugment. Do you really understand how monads work? And do you know how do notation translates to calls using >>=?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.