如何將連接的String
轉換爲Turtle FilePath
?例如,下面的程序試圖讀取一些文本文件,將它們連接成一個新文件並刪除舊文件。它似乎沒有工作雖然OverloadedStrings
擴展啓用:將字符串轉換爲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
拋出的錯誤是:
Couldn't match expected type ‘Turtle.FilePath’
with actual type ‘[Char]’
In the first argument of ‘output’, namely
‘(show n ++ "-" ++ show k ++ ".txt")’
切換到output "example.txt" concat
也只是正常工作。是不是String
只是[Char]
的類型別名?
'fromString'列出[here](http://hackage.haskell.org/package/turtle-1.2.8/docs/ Turtle.html)可能工作。 – pdexter
但是您可能應該使用turtle的'Format'接口找到[這裏](http://hackage.haskell.org/package/turtle-1.2.8/docs/Turtle-Format.html) – pdexter