CS计算机代考程序代写 Haskell This file is now a LaTeX file with embedded Haskell:

This file is now a LaTeX file with embedded Haskell:
\begin{code}
module Jan12b where

— let’s play with lists a little
— recall
— data [] a = [] | a : [a]
map’ :: (a -> b) -> [a] -> [b]
map’ f [] = []
map’ f (x : xs) = f x : map’ f xs

filter’ :: (a -> Bool) -> [a] -> [a]
filter’ p [] = []
filter’ p (x : xs) | p x = x : filter’ p xs
| otherwise = filter’ p xs

isEven :: Integer -> Bool
isEven x = x `mod` 2 == 0

— Things we tried:
— 7 `mod` 2
— filter’ isEven [(-15)..15]

— list comprehension:
— [ x | x <- l, isEven x] -- rather list 'set' comprehension in math -- { x \in l | isEven x } l :: [Integer] l = [-15..15] -- -- if we want to print something, like this: main :: IO () main = print "Hello World!" \end{code}