import Prelude hiding (take) f x = 1 loop = loop m = f loop -- > (Haskell!!!) 1 -- Lazy Evaluation: -- evaluate an expression only if needed (--> needed evaluation): -- because of case distinction or pattern matching -- Advantages: -- * less computational work -- * computing with infinite data structures -- An infinite list of increasing numbers: from :: Int -> [Int] from n = n : from (n+1) -- Returns the prefix with n elements of a list: take :: Int -> [a] -> [a] take n xs | n <= 0 = [] | otherwise = case xs of [] -> [] y:ys -> y : take (n - 1) ys sieve :: [Int] -> [Int] sieve (p:xs) = p : sieve (filter (\x -> x `mod ` p > 0) xs) primes :: [Int] primes = sieve (from 2) -- principle: separate data generation (primes) and control (take, !!)