RE: Coding Challenge #2 – Polynomial
There are three parsers related to polynomials: poly term and number.
Line 15: All parsers remove the trailing spaces, so the main parser poly should remove the leading whitespace. It basically states: skip the whitespace, poly is made of many terms and you arrive to the end of the input.
Line 18: term is a tuple of a number and another number. The second number is located after an identifier and the symbol ^.
Line 21-25: number is either negative or positive. <|> stands for either. For the second case the number may not start with the sign +, option takes care of that. f computes the value of the string of numbers.
Line 28: We run the parser poly on the sample input. It prints out the result as a tuple of terms as indicated in the parser descriptions.
Thank you for the explanation! Parsec is really strong, looking forward to leaning more about it :)
It is and I'm using it in very basic form. There're very good documents at https://github.com/haskell/parsec