CS计算机代考程序代写 Haskell — Example code for Jan12, to get people reacquainted with Haskell

— Example code for Jan12, to get people reacquainted with Haskell
module Jan12 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!"