2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 06:18:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/haskell/polynome.hs
2014-03-18 19:31:04 +01:00

16 lines
No EOL
361 B
Haskell

type Polynom = [Double]
add :: Polynom -> Polynom -> Polynom
add a [] = a
add [] a = a
add (x:xs) (y:ys) = (x+y) : add xs ys
eval :: Polynom -> Double -> Double
eval [] x = 0
eval (p:ps) x = p + x * (eval ps x)
-- alternativ:
eval p x = foldr (\element rest ->element+x*rest) 0 p
deriv :: Polynom -> Polynom
deriv [] = []
deriv p = zipWith (*) [1..] (tail p)