Last active
December 29, 2015 11:14
-
-
Save acamino/ba3cd6bf86a86d347069 to your computer and use it in GitHub Desktop.
CIS 194 Week 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Prelude functions which are defined in terms of foldr | |
-- http://www.cis.upenn.edu/~cis194/spring13/lectures/04-higher-order.html | |
length' :: [a] -> Int | |
length' = foldr (\_ acc -> 1 + acc) 0 | |
sum' :: Num a => [a] -> a | |
sum' = foldr (*) 1 | |
product' :: Num a => [a] -> a | |
product' = foldr (*) 1 | |
and' :: [Bool] -> Bool | |
and' = foldr (\e acc -> e && acc) True | |
or' :: [Bool] -> Bool | |
or' = foldr (\e acc -> e || acc) False | |
any :: (a -> Bool) -> [a] -> Bool | |
any' p = foldr(\e acc -> p e || acc) False | |
all' :: (a -> Bool) -> [a] -> Bool | |
all' p = foldr(\e acc -> p e && acc) True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment