title: Is there a way to rewrite this function to be total?
body: <p>I have a function, shown below, which someone on Code Review suggested I rewrite to be total. They suggested that the calls to <code>getRow</code> and <code>(!)</code> could be replaced with calls to <code>zip</code> or <code>fold</code>.</p>
  
  <p>I've thought about this and I can't really see how to rewrite it that way, nor do I have a good sense of how I would teach myself how to rewrite it. </p>
  
  <pre class="lang-hs prettyprint-override"><code>import Data.Matrix (Matrix, getRow, ncols)
  import Data.Vector ((!))
  
  type AdjacencyMatrix = Matrix Bool
  
  -- Input: the graph's adjacency matrix and a vertex. 
  -- Output: the list of neighbours of that vertex.
  neighbours :: AdjacencyMatrix -&gt; Int -&gt; [Int]
  neighbours mat n = filter (\m -&gt; row ! m) [0..(ncols mat)-1]
          where row = getRow n mat
  </code></pre>
  
  <p>This code snippet works within the context of my program, but if <code>n</code> is larger than <code>(ncols mat) - 1</code> then some of the <code>row ! m</code> calls will fail.</p>