title: Creating list of Polygons from a text file in Haskell
body: <p>I have read a file of numbers and created a list of numbers from it, now I would like to create a list of Polygons based on the numbers in the list as they have a specific layout/pattern. </p>
  
  <pre><code>type Point = (Double, Double)
  
  data Polygon = Polygon { v :: Int
                         , y :: Int
                         , points :: [Point]  
                         }
  
  main = do  
      let list = []
      handle &lt;- openFile "polycake.in" ReadMode
      contents &lt;- hGetContents handle
      let singlewords = words contents
          list = fileToList singlewords
          n = list!!0
          list' = drop 1 list
          polygons = polyList n list'  
      hClose handle 
  
  fileToList :: [String] -&gt; [Int]
  fileToList = map read
  
  polyList :: Int -&gt; [Int] -&gt; [Polygon]
  polyList n [] = return []
  polyList n list = do
      let v = list!!0
          y = list!!1
          list' = drop 2 list
          pointList = take (2*v) list'
          points = getPoints pointList
          list'' = drop (2*v) list'
          poly = Polygon { v = v, y = y, points = points}
          nextPoly = polyList (n-1) list''
      return (poly:nextPoly)
  
  getPoints :: [Int] -&gt; [Point]
  getPoints (k:v:t) = (fromIntegral k, fromIntegral v) : getPoints t
  </code></pre>
  
  <p>However I am getting the errors:</p>
  
  <pre><code>polycake.hs:27:17: error:
       • Couldn't match type ‘[a0]’ with ‘Polygon’
        Expected type: [Polygon]
          Actual type: [[a0]]
       • In the expression: return []
        In an equation for ‘polyList’: polyList n [] = return []
     |
  27 | polyList n [] = return []
     |                 ^^^^^^^^^
  
  polycake.hs:37:5: error:
      • Couldn't match type ‘[Polygon]’ with ‘Polygon’
        Expected type: [Polygon]
          Actual type: [[Polygon]]
      • In a stmt of a 'do' block: return (poly : nextPoly)
        In the expression:
          do let v = list !! 0
                 y = list !! 1
                 ....
             return (poly : nextPoly)
        In an equation for ‘polyList’:
            polyList n list
              = do let v = ...
                       ....
                   return (poly : nextPoly)
     |
  37 |     return (poly:nextPoly)
     |     ^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>I am unsure why I am getting these errors.</p>
  
  <p>Sample polycake.in:</p>
  
  <pre><code>2
  4 2
  0 0
  4 0
  4 4
  0 4
  6 10
  3 15
  10 1
  12 5
  11 19
  9 23
  6 20
  </code></pre>
  
  <p>So the first line is the # of test cases, for each test case starts with 2 numbers, the first being the number of vertices and the second being a y value that is used for a later calculation. Then the following v pairs are the vertices or Points.</p>