title: Listing a TAR archive in Haskell
body: <p>I'm currently trying to figure out how to list a (gzipped) TAR archive in Haskell. <a href="http://hackage.haskell.org/package/tar-0.4.0.1/docs/Codec-Archive-Tar.html" rel="nofollow"><code>Codec.Archive.Tar</code></a> seems to be the right choice for the task, but I can't figure out how <code>map</code> the <code>entryPath</code> over the <code>Entries</code> monoid.</p>
  
  <p>Let's assume the TAR contains the entries (only files) <code>a.txt, b.txt, c.txt</code> and is named <code>foo.tar.gz</code>. Here's my code to read the file:</p>
  
  <pre><code>import qualified Codec.Archive.Tar as Tar
  import qualified Data.ByteString.Lazy as BS
  import qualified Codec.Compression.GZip as GZip
  
  foldEntryToPath :: Tar.Entry -&gt; [String] -&gt; [String]
  foldEntryToPath entry list = list ++ [show $ Tar.entryPath entry]
  
  -- Converts TAR errors to a string.
  entryFailMapper :: String -&gt; [String]
  entryFailMapper err = [err]
  
  main = do
          fileContent &lt;- fmap GZip.decompress $ BS.readFile "foo.tar.gz"
          entries &lt;- fmap Tar.read fileContent :: Tar.Entries
          -- Here I don't know how to correctly apply fmap
          entryPaths &lt;- Tar.foldEntries foldEntryToPath [] entryFailMapper entries :: [String]
          -- This should print ["a.txt", "b.txt", "c.txt"]
          print entryPaths
  </code></pre>
  
  <p>Here's the error printed by <code>runghc</code>:</p>
  
  <pre><code>readtar.hs:14:49:
  Expecting one more argument to `Tar.Entries'
  In an expression type signature: Tar.Entries
  In a stmt of a 'do' block:
    entries &lt;- fmap Tar.read fileContent :: Tar.Entries
  In the expression:
    do { fileContent &lt;- fmap GZip.decompress
                        $ BS.readFile "foo.tar.gz";
         entries &lt;- fmap Tar.read fileContent :: Tar.Entries;
         entryPaths &lt;- Tar.foldEntries
                         foldEntryToPath [] (\ x -&gt; [...]) entries ::
                         [String];
         print entryPaths }
  </code></pre>
  
  <p>So far I have little knowledge of Haskell, but by reading <a href="http://hackage.haskell.org/package/tar-0.4.0.1/docs/Codec-Archive-Tar.html" rel="nofollow">the docs</a> I don't know why <code>Tar.Entries</code> is a typeclass (is that the correct term when it says <code>expecting n more arguments to &lt;type&gt;</code>?) or what's the correct type to use.</p>
  
  <p>Any help will be appreciated!</p>