mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-25 22:38:04 +02:00
Fixpunktkombinatoren; Haskell-Beispiele
This commit is contained in:
parent
e910561dfe
commit
0174aa0cc6
5 changed files with 129 additions and 6 deletions
15
documents/Programmierparadigmen/scripts/haskell/Intersect.hs
Normal file
15
documents/Programmierparadigmen/scripts/haskell/Intersect.hs
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Intersect where
|
||||
intersect :: (Ord t) => [t] -> [t] -> [t]
|
||||
intersect a [] = []
|
||||
intersect [] a = []
|
||||
intersect (x:xs) (y:ys)
|
||||
| x == y = x : intersect xs ys
|
||||
| x < y = intersect xs (y:ys)
|
||||
| y > y = intersect (x:xs) ys
|
||||
|
||||
intersectAll :: (Ord t) => [[t]] -> [t]
|
||||
intersectAll (l:ls) = (foldr intersect l) ls
|
||||
intersectAll [] = undefined
|
||||
|
||||
multiples n = [n*k | k <- [1..]]
|
||||
commonMultiples a b c = intersectAll [ multiples n | n <- [a,b,c]]
|
|
@ -0,0 +1,2 @@
|
|||
fibs :: [Integer]
|
||||
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
|
Loading…
Add table
Add a link
Reference in a new issue