2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 22:38:04 +02:00

Haskell-Beispiele hinzugefügt

This commit is contained in:
Martin Thoma 2014-03-18 19:31:04 +01:00
parent 137a44cd5e
commit 8e73ed0910
6 changed files with 69 additions and 2 deletions

View file

@ -0,0 +1,16 @@
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)