Implemented exercise 3 for List.hs