-- book.hs: code to process a list of books and print the year data BookInfo = Book Int String [String] deriving (Show) year (Book yr title authors) = yr allYears [] = [] allYears (book:rest) = (year book) : (allYears rest) -- aveYear: average of years of all books in library -- Not defined if library is empty aveYear library = let years = allYears library in (fromIntegral (sum years)) / (fromIntegral (length years)) -- testData lib = [Book 1851 "Moby Dick" ["Herman Melville"], Book 1851 "The House of the Seven Gables" ["Nathaniel Hawthorne"], Book 1937 "The Hobbit" ["JRR Tolkien"], Book 1990 "Good Omens" ["Terry Pratchett", "Niel Gaiman"] ] -- aveYear lib should return 1907.25