Without looking at the standard prelude, define the following library functions
ID: 2875849 • Letter: W
Question
Without looking at the standard prelude, define the following library functions using recursion:
1. Decide if all logical values in a list are true:
and :: [Bool] -> Bool
2. Decide if a value is an element of a list:
elem :: Eq a => a -> [a] -> Bool
Explanation / Answer
• Decide if all logical values in a list are True: myAnd :: [Bool] -> Bool myAnd [] = True myAnd (False:rest) = False myAnd (True:rest) = myAnd rest • Decide if a value is an element of a list: myElem :: Eq a => a -> [a] -> Bool myElem target [] = False myElem target (element:elements) | target == element = True | otherwise = myElem target elements
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.