title: Rewriting python arrays manipulation function in haskell
body: <p>So I wanted to try to rewrite my pivot routine in haskell, but I got stuck right away...</p>
  
  <p>Here is my original python routine (i've commented it heavily to compensate for the lack of types): </p>
  
  <pre><code>def pivot(entering, leaving, B, A, Z):
      """
      @param entering integer indicating the entering col #
      @param leaving integer indicating the leaving col #
      @param B vector/array of integers, representing the basis
      @param A matrix of floating point numbers
      @param Z vector/array of floating point numbers
      returns tuple:
          (B, A, Z) with pivoted tableau
      """
  
      # Copy A
      M = [row for row in A]
      # Append Z row to the matrix
      M.append(Z)
  
      # Find the main row
      eq_no = B.index(leaving)
      col = entering
  
      # Go through all other rows and do Gaussian elimination on them:
      for i in range(len(M)):
          if i == eq_no:
              continue
          # Do pivot - ignore "zero_out" function for now
          #            assume it returns a vector same size as row M[i]
          M[i] = zero_out(M[i], M[eq_no], col)
  
      # Reassign B's
      Bprime = [b for b in B]  # copy B
      Bprime[eq_no] = entering  # replace
  
      # return new B, matrix M (less 1 row), and last row of M
      return (Bprime, M[:len(M)-1], M[len(M)-1])
  </code></pre>
  
  <p>Here is how far I got...</p>
  
  <pre><code>type Matrix = [ [Double] ]
  type Vector = [ [Vector] ]
  
  matrix = [ [1, 2, 3], [2, 3, 4]]
  hello:: Matrix -&gt; Int
  hello m = length m
  
  pivot:: Int -&gt; Int -&gt; Vector -&gt; Matrix -&gt; Matrix -&gt; Matrix
  pivot entering leaving b a z = 
      let m = a::z
          eq_no = elemIndex leaving b
          case eq_no of
              Just no -&gt; no
              Nothing -&gt; 1
          col = entering
  
      in  ????
  </code></pre>
  
  <p>I am very interested in how people might implement the "matrix" and "vector" types, and also how they will manipulate the arrays - like replacing elements in them or rows in a matrix.</p>
  
  <p>Let me know if something is not clear, and thanks!</p>