Problem Sheet 1 --------------- This problem sheet is to get you started on Haskell programming and for familiarity with the Haskell interpreter Hugs. The TAs will help you in solving these problems. Though your answers will not be graded, you will have to submit the assignment. 1. Consider a representation of matrices as lists where the matrix | a b c | | d e f | is represented as [[a,b,c],[d,e,f]] Call this matrix m. Now define the following functions on matrices. Use higher order functions as much as possible. 1. A function firstcol, such that (firstcol m) will return [[a],[d]]. 2. A function lastcols, such that (lastcols m) will return [[b,c],[e,f]]. 5. A function dot-product with the obvious meaning. 4. A function transpose which will transpose a matrix. 3. A function matmult which will return the multiplication of two matrices. 2. (a) Using foldr write a function called inits which finds all the initial segments of a list. Examples: (inits []) = [[]] (inits [1,2,3,4]) = [[],[1],[1,2],[1,2,3],[1,2,3,4]] (b) Once again using foldr write a function tails which will find all the tail segments of a list. Examples: (tails []) = [[]] (tails [1,2,3,4] = [[],[4],[3,4],[2,3,4],[1,2,3,4]] (c) Now using inits tails and map define a function called sublists which will find all the sublists of a list. Example: (sublist []) = [[]] (sublist [1,2,3,4]) = [[],[1] [1,2] [1,2,3],[1,2,3,4],[2],[2,3], [2,3,4],[3] [3,4],[4]] 3. A general tree is defined by the datatype declaration: data Gtree a = Gnode a [Gtree a] Define functions dft :: Gtree a -> [a], and bft :: Gtree a -> [a] which will do depth-first traversals and breadth-first traversals over general trees.