如何将连接的转换String
为 Turtle FilePath
?例如,以下程序尝试读取一些文本文件,将它们连接成一个新文件并删除旧文件。OverloadedStrings
尽管启用了扩展,但它似乎不起作用:
{-# 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]
吗?