Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Matthew Larson Exercise 2.2 10/7/2019
- import Prelude hiding (sum)
- sum :: Num n => [n] -> n
- sum [] = 0
- sum (x:xs) = x + sum xs
- -- | Square a number
- square :: Num n => n -> n
- square x = x^2
- sumProducts :: Num n => [n] -> n
- sumProducts = product . map square
- divisibleBy :: Integral n => n -> n -> Bool
- divisibleBy d n = d `mod` n == 0
- result = sum
- . take 100
- . filter (divisibleBy 2)
- . filter (divisibleBy 3)
- . filter (not . divisibleBy 4)
- . filter (not . divisibleBy 9)
- $ [0..]
- allp :: [a-> Bool] -> Bool -> Bool
- allp [] x = False
- allp (p:ps) x
- | p x = allp ps x
- | otherwise = False
- filterAll :: (a-> [b]) -> (c -> Bool)-> [a]
- filterAll filter . (allp (c:cs)) = c: filterAll filter allp cs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement