You are viewing a single comment's thread from:

RE: Coding Challenge #2 – Polynomial

in #coding-challenge7 years ago

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.

Sort:  

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

Coin Marketplace

STEEM 0.21
TRX 0.26
JST 0.040
BTC 101296.09
ETH 3673.80
USDT 1.00
SBD 3.15