FoP Exercises 2
28-Mar-2002
School of Computer and Communication Sciences
Programming Methods Laboratory (LAMP)
 
 
Home
Staff
Research
Publications
Events
Teaching
  FoP
    Overview
    Schedule
    Slides
    Tutorial
    Contact
    Links
Jobs
   
 
  
     

In functional programming languages, matrices are often implemented as lists of rows, where each row is itself a list of values. The matrix

would be encoded like this:

[[x11, x12, x13], [x21, x22, x23]]
Implement support for matrices and vectors in Funnel. Your abstraction should at least include the following functions operating on matrices and vectors:
  • scalarprod computes the scalar product of two vectors,
  • transpose transposes a given matrix,
  • add adds two matrices, and
  • mult multiplies two matrices
You can copy a framework for this exercise from the following location: /home/linuxsoft/funnel/lecture/Matrix.fn. You should also copy .../lecture/List.fn, .../lecture/String.fn, .../lecture/Java.fn and .../lecture/Console.fn. This framework loads a predefined list type, so that all important list operations can be used easily. This implementation of lists uses an object-oriented style. Here is a transcript of a funni session: funni -untyped List.fn
> with List: ListModule
()
> val l1 = Cons(1, Cons(2, Cons(3, Nil)))
'val l1 = '
> l1.toString
"[1, 2, 3]"
> val l2 = 1 :: 2 :: 3 :: Nil
'val l2 = '
> l2.toString
"[1, 2, 3]"
> l1.append(l2).toString
"[1, 2, 3, 1, 2, 3]"
> l1.append(l2).map(x|"number " + x).toString
"[number 1, number 2, number 3, number 1, number 2, number 3]"

          
     
   [an error occurred while processing this directive]  
Last modified: Monday, 01-Mar-2004 14:31:03 CET