mercredi 29 avril 2015

Batch modify files Haskell

I am trying to create a program that adds a simple text header to every file in a directory (and its subdirectories). I need to do this just using the built in functions from ghc (I can't access cabal).

The type signature of the functions are

getRecursiveContents :: FilePath -> IO [FilePath]

addHeaderToFile :: String -> FilePath -> IO ()

These both work fine independently but I am struggling to use the two functions in conjunction because of the types. I assumed using a map would be the correct way to do this, but so far I have been unsuccessful.

addHeaderToMultiple :: String -> IO [FilePath] -> IO ()
addHeaderToMultiple header files = map (addHeaderToFile header) files

I understand this will not work due to the types used but I have not found a way to fix it.

Aucun commentaire:

Enregistrer un commentaire