title: Haskell, Knapsack not expected return types error recieved
body: <p>Here is my code to solve the fractional knapsack problem, input to knap should be in the form </p>
  
  <pre><code>[("label 1", value, weight), ("label 2", value, weight), ...]
  </code></pre>
  
  <p>And output should be in the form</p>
  
  <pre><code>[("label 1", value, solution_weight), ("label 2", value, solution_weight), ...]
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import Data.List {- Need for the sortBy function -}
  {- Input "how much can the knapsack hole &lt;- x" "Possible items in sack [(label, value, weight), ...] &lt;- y" -}
  {-knap x [([Char], Integer, Integer), ... ] = -}
  knap x [] = []
  knap x y = if length y == 1 
      then 
          if x &gt; last3 (head y)
              then y
              else [(frst3 (head y), scnd3 (head y), x)]
      else 
          knap2 x y []
  {- x is the knap max, y is the sorted frac list, z is the solution list -}
  knap2 x y z = if x == 0
      then z
      else
          if thrd4 (head y) &gt; x
              then [((frst4 (head y)), (scnd4 (head y)), x)]
              else knap2 (x-(thrd4 (head y))) (tail y) (z++[((frst4 (head y)), (scnd4 (head y)), (thrd4 (head y)))]) 
  
  {- take a list of labels, values, and weights and return list of labels and fractions -}
  fraclist :: (Fractional t1) =&gt; [(t, t1, t1)] -&gt; [(t, t1, t1, t1)]
  fraclist xs = [(x, y, z, y/z) | (x, y, z) &lt;- xs]
  
  {- Sort the list -}
  sortList x = sortBy comparator x
      where comparator (_,_,_,d) (_,_,_,h) = if d &gt; h then LT else GT
  
  {- helper func to get values from tuples -}
  frst3 (a,b,c) = a
  scnd3 (a,b,c) = b
  last3 (a,b,c) = c
  frst4 (a,b,c,d) = a
  scnd4 (a,b,c,d) = b
  thrd4 (a,b,c,d) = c
  last4 (a,b,c,d) = d
  </code></pre>
  
  <p>Here is the error I am getting</p>
  
  <pre><code>Couldn't match expected type `(t1, t0, t2, t3)'
              with actual type `(t1, t0, t2)'
  Expected type: [(t1, t0, t2, t3)]
    Actual type: [(t1, t0, t2)]
  In the second argument of `knap2', namely `y'
  In the expression: knap2 x y []
  </code></pre>
  
  <p>I am not quite sure what else I can do. before I sit here and bang my head on the wall for an hour maybe someone could point out an obvious mistake if there are any?</p>