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:
parent
137a44cd5e
commit
8e73ed0910
6 changed files with 69 additions and 2 deletions
16
documents/Programmierparadigmen/scripts/haskell/polynome.hs
Normal file
16
documents/Programmierparadigmen/scripts/haskell/polynome.hs
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue