list - SML - Multiplying Coefficients of Polynomials -


I have two lists that include coefficients for two different polynomials, and I'm looking to write a function I am able to multiply them together (i.e. FOIL)

Funny polymalt (zero, zero) = zero. Polyalt (X as X :: X, NY: ys) = (x * y): Polyalt (xs, ys);

Am I on the right track?

In addition, I have an error message in which unselected exception match [impossible match failure]

What does this mean?

Unfortunately, you are not on the right track. Your work only zips two lists with multiplication, which That's not how FOIL works. According to the definition of polynomial multiplication, your function should return a polynomial of a higher level. You should be able to understand the FO-IL.

Anything wrong match means that you are not covering all possible cases for two lists in your pattern matching. In fact, you are not missing two cases where one of the lists is zero and the second is not. In the context of your function, this will mean in cases where the function lists the coefficients of various levels of polynomials.

If you are currently unavailable, you want to handle those two cases separately, you can go like this:

  Funny polymalt (M, N) = Case (M, N) ([], []) & gt; [] | ([], Y: ys) => ... | (X :: xs, []) & gt; ... | (X :: xs, y :: ys) = & gt; ...  

Of course, replace the dots with your implementation. I hope it helps, good luck.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Algorithm negotiation fail SSH in Jenkins -

java - Messages from .properties file do not display UTF-8 characters -