Comment puis-je convertir un String
concaténé en un Turtle FilePath
? Par exemple, le programme suivant essaie de lire certains fichiers texte, de les concaténer en un nouveau et de supprimer les anciens. Il ne semble pas fonctionner même si l'extension OverloadedStrings
est activée:Convertir la chaîne en Turtle.FilePath
{-# LANGUAGE OverloadedStrings #-}
module Main where
import System.Environment
import System.IO
import Control.Monad
import Turtle
import Turtle.Prelude
import qualified Control.Foldl as L
main :: IO()
main = do
params <- getArgs
let n = read $ params !! 0
k = read $ params !! 1
-- Some magic is done here
-- After a while, read generated .txt files and concatenate them
files <- fold (find (suffix ".txt") ".") L.list
let concat = cat $ fmap input files
output (show n ++ "-" ++ show k ++ ".txt") concat
-- Remove old .txt files
mapM_ rm files
L'erreur est jeté:
Couldn't match expected type ‘Turtle.FilePath’
with actual type ‘[Char]’
In the first argument of ‘output’, namely
‘(show n ++ "-" ++ show k ++ ".txt")’
Le passage à output "example.txt" concat
serait tout simplement fonctionner correctement. N'est-ce pas String
juste un alias de type [Char]
?
'fromString' répertorié [ici] (http://hackage.haskell.org/package/turtle-1.2.8/docs/ Turtle.html) pourrait fonctionner. – pdexter
Mais vous devriez probablement utiliser l'interface 'Format' de tortue trouvée [ici] (http://hackage.haskell.org/package/turtle-1.2.8/docs/Turtle-Format.html) – pdexter