F# functions implementing polynomial arithmetic I have a couple of functions for doing basic arithmetic on polynomials.

let rec mulC x ys =
match (x,ys) with
| (_,[])                    -&gt; []
| (x,y::ys) when x &gt; 0    -&gt; x * y::mulC x ys

let rec addE xs ys =
match (xs, ys) with
| ([],[])                   -&gt; []
| ([], y::ys)            -&gt; y::ys
| (x::xs,[])             -&gt; x::xs
| (x::xs, y::ys)      -&gt; (x + y) :: addE xs ys

let mulX xs = 
match xs with
| []                    -&gt; []
| xs                    -&gt; 0::xs

let rec mul qs = function
| []                    -&gt; []
| x::tail               -&gt; addE (mulC x qs)
                                (mulX(mul qs tail))
| (x,y::ys) when x &gt; 0    -&gt; x * y::mulC x ys






| (x::xs, y::ys)      -&gt; (x + y) :: addE xs ys



Why the inconsistency in parentheses and whitespace? For what it's worth, I think the second is more readable.




let rec mulC x ys =
match (x,ys) with
| (_,[])                    -&gt; []
| (x,y::ys) when x &gt; 0    -&gt; x * y::mulC x ys



What about the case x = 0, ys is non-empty? Don't you get a warning? (I also find it odd that the test is &gt;. I infer that you're only intending to handle non-negative coefficients, but that seems like an unnecessary restriction).




let rec addE xs ys =
match (xs, ys) with
| ([],[])                   -&gt; []
| ([], y::ys)            -&gt; y::ys
| (x::xs,[])             -&gt; x::xs
| (x::xs, y::ys)      -&gt; (x + y) :: addE xs ys



There's no need to pattern-match a structure if you're not using the structure. This could be simplified to

let rec addE xs ys =
  match (xs, ys) with
  | ([], ys)            -&gt; ys
  | (xs,[])             -&gt; xs
  | (x::xs, y::ys)      -&gt; (x + y) :: addE xs ys




Why are the three auxiliary functions in the top-level scope? I admit that I don't know F#, but the languages that it's heavily inspired by would allow them to be defined in a let clause inside the definition of mul, keeping the top-level namespace clean.