There are many ways to solve this problem.... This would be my order of preference.
Use a parser lib, like Parsec.
Use a regex.
Use Prelude functions like splitAt.
But since you can't use any libs, you will have to go with messy solution 4.
- Write everything by hand using just pattern matching.
You've already shown us how to match the int part, so you just need the remaining stuff. Since this is homework, I won't give you the answer, but give you one possible outline.
What you could do is break the problem into parts, and write multiple matcher functions of the type
showPart::String->String
where the parts would be something like showVarName, showEq, etc. Each part would need to consume part of the text, then call the next part (so ultimately you would only need to call the first part, the rest woulc be consumed in order). The only large modification from what you have above would be the need for recursion in variable length parts, like showVarName.
showVarName (c:rest) | isAlphanum c = c ++ showVarName
showVarName x = .... --call the next part here
(yes, I added a new function isAlphaNum.... You will need something like it, although it could be written using pattern matching if needed)
This will solve the problem, but note that the solution will be very brittle.... It will be hard to make any changes, to the ordering of the parts, to the type (what if the RHS can be a variable, or a full expression), to the allowed formats (ie- what if varname can be of form [alpha][alphaNum]*), or the output (what if you want to output a fully parsed expression tree, then use that in multiple ways, including plugging that into a show function).
In practice no one would ever really parse this way, and I am assuming that that might be one of the lessons that your prof. may be trying to illustrate for you.