Haskell local function Is not in scope -


the following function supposed return sum of polynomials in list having polynomial list of floats. (ie: 4x²+2x+1 [4,2,1] , 5x⁵+x+2 [5,0,0,0,1,2])

psum :: [[float]] -> [float] psum (x1:x2:xs) = psum (binpsum (x1, x2)):xs psum x = x       binpsum (x:xs) (y:ys) = x+y:binpsum (xs, ys)              binpsum (x) (y:ys) = x+y:ys             binpsum (x:xs) (y) = x+y:xs 

i'm getting

 not in scope: ‘binpsum’ 

it's first time work haskell i'd guess there's wrong in way use binpsum (x1, x2) since can't find wrong in clause.

thanks!

the where clause provides bindings equation directly above (or left) of it. can fix moving up, under first of equation of psum used.

other that, there various additional misunderstandings i'm seeing in code:

  1. when function defined f x y, must called (not f (x, y)).
  2. if want pattern match against single item in list, must enclose item in square brackets indicate indeed item want bind, , not list itself.
  3. if argument function expression of more 1 word/symbol, need enclose in brackets (e.g. f (a + b) instead of f + b).

here version of code compiles:

psum :: [[float]] -> [float] psum (x1:x2:xs) = psum (binpsum x1 x2 : xs)     binpsum (x:xs) (y:ys) = x+y : binpsum xs ys           binpsum [x] (y:ys) = x+y : ys           binpsum (x:xs) [y] = x+y : xs psum [x] = x 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -