Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| pp:lecture12 [2022/04/19 12:48] pdmatei | pp:lecture12 [2022/04/19 12:50] (current) pdmatei | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== L10. Lazy evaluation ====== | + | ====== L12. Lazy evaluation ====== | 
| <code haskell> | <code haskell> | ||
| Line 76: | Line 76: | ||
| -- [x, f x, f f x, f f f x, ....] | -- [x, f x, f f x, f f f x, ....] | ||
| - | ex' = zipWith (,) (gen (+1) 0) (gen (*2) 1) | + | exx = zipWith (,) (gen (+1) 0) (gen (*2) 1) | 
| Line 86: | Line 86: | ||
| we need to filter out numbers divisible by 2 from the rest of the stream: | we need to filter out numbers divisible by 2 from the rest of the stream: | ||
| - | filter (\n-> n `mod` 2 /= 0) rest | + | filter (\k-> k `mod` 2 /= 0) rest | 
| 3,_,5,_,7,_,9,_,11,_,13,_,15,_,17,_,19,_,21,_,23,_,25 | 3,_,5,_,7,_,9,_,11,_,13,_,15,_,17,_,19,_,21,_,23,_,25 | ||
| Line 96: | Line 96: | ||
| -} | -} | ||
| + | |||
| sieve :: [Integer] -> [Integer] | sieve :: [Integer] -> [Integer] | ||
| - | sieve (x:xs) = x:(sieve $ filter (\n-> n `mod` x /= 0) xs) | + | sieve (x:xs) = x:(sieve $ filter (\k-> k `mod` x /= 0) xs) | 
| primes = sieve $ tail $ tail nats | primes = sieve $ tail $ tail nats | ||