content: {-# OPTIONS_GHC -Wall #-}
  
  module Lecture where
  
  data IntList = Empty | Cons Int IntList
    deriving Show
  
  absAll :: IntList -> IntList
  absAll Empty       = Empty
  absAll (Cons x xs) = Cons (abs x) (absAll xs)
  
  squareAll :: IntList -> IntList
  squareAll Empty = Empty
  squareAll (Cons x xs) = Cons (x*x) (squareAll xs)
  
  myMap :: (Int -> Int) -> IntList -> IntList
  myMap _ Empty = Empty
  myMap f (Cons x xs) = Cons (f x) (myMap f xs)
  
  keepOnlyEven :: IntList -> IntList
  keepOnlyEven Empty = Empty
  keepOnlyEven (Cons x xs)
    | even x    = Cons x (keepOnlyEven xs)
    | otherwise = keepOnlyEven xs
  
  filterIntList :: (Int -> Bool) -> IntList -> IntList
  filterIntList _ Empty = Empty
  filterIntList f (Cons x xs)
    | f x       = Cons x (filterIntList f xs)
    | otherwise = filterIntList f xs
  
  data List t = E | C t (List t)
    deriving Show
  
  filterList :: (t -> Bool) -> List t -> List t
  filterList _ E = E
  filterList p (C x xs)
    | p x       = C x (filterList p xs)
    | otherwise = filterList p xs
  
  mapList :: (a -> b) -> List a -> List b
  mapList _ E = E
  mapList f (C x xs) = C (f x) (mapList f xs)
  