title: Retrieve strings from Matrix
body: <p>I'm stuck with my homework task, somebody help, please..</p>
  
  <p>Here is the task:
  Find all possible partitions of string into words of some dictionary</p>
  
  <p>And here is how I'm trying to do it:
  I use dynamical programming concept to fill matrix and then I'm stuck with how to retrieve data from it</p>
  
  <pre><code>-- Task5_2
  retrieve :: [[Int]] -&gt; [String] -&gt; Int -&gt; Int -&gt; Int -&gt; [[String]]
  retrieve matrix dict i j size
      | i &gt;= size || j &gt;= size = []
      | index /= 0 = [(dict !! index)]:(retrieve matrix dict (i + sizeOfWord) (i + sizeOfWord) size) ++ retrieve matrix dict i (next matrix i j) size
      where index = (matrix !! i !! j) - 1; sizeOfWord = length (dict !! index)
  
  
  next matrix i j
      | j &gt;= (length matrix) = j
      | matrix !! i !! j &gt; 0 = j
      | otherwise = next matrix i (j + 1)
  
  getPartitionMatrix :: String -&gt; [String] -&gt; [[Int]]
  getPartitionMatrix text dict = [[ indiceOfWord (getWord text i j) dict 1  | j &lt;- [1..(length text)]] | i &lt;- [1..(length text)]]
  
  --------------------------
  getWord :: String -&gt; Int -&gt; Int -&gt; String
  getWord text from to = map fst $ filter (\a -&gt; (snd a) &gt;= from &amp;&amp; (snd a) &lt;= to) $ zip text [1..]
  
  
  indiceOfWord :: String -&gt; [String] -&gt; Int -&gt; Int
  indiceOfWord _ [] _ = 0
  indiceOfWord word (x:xs) n
      | word == x  = n
      | otherwise = indiceOfWord word xs (n + 1)
  
  
  -- TESTS
  dictionary = ["la", "a", "laa", "l"]
  string = "laa"
  matr = getPartitionMatrix string dictionary
  test = retrieve matr dictionary 0 0 (length string)
  </code></pre>