我需要从cp_r库执行雪莱函数,以便将a复制到b。
然而,
import Shelly
main = do cp_r "a" "b"收益率
Couldn't match expected type `Shelly.FilePath'
with actual type `[Char]'
In the first argument of `cp_r', namely `"a"'
In the expression: cp_r "a" "b"
In an equation for `it': it = cp_r "a" "b"用于cp_r的第一个和第二个参数。
如何使用String (FilePath定义为在我所知道的任何平台上的字符串)作为cp_r的参数
注意:这个问题没有表现出任何研究的努力,因为它被回答了问答式.
发布于 2014-02-11 23:55:04
有关详细的官方描述,请参阅关于黑客的文本与FilePath之间的转换部分。
让我们首先看看如何使用Text来完成它
{-# LANGUAGE OverloadedStrings #-}
import Shelly
cp_r (fromText "a") (fromText "b")从现在开始,我们只需使用Text.pack将此方法应用于字符串。
{-# LANGUAGE OverloadedStrings #-}
import Shelly
import Data.Text
cp_r (fromText $ pack "a") (fromText $ pack "b")请注意,如果您还需要在模块中使用来自FilePath的Prelude,则需要使用
import Shelly hiding (FilePath)为了避免冲突(或者可以使用Prelude.FilePath和Shelly.FilePath)。
发布于 2014-02-12 07:04:32
我同意@Uli Kohler -以下是这种用法的一个例子:
https://github.com/haroldcarr/make-mp3-copies/blob/master/MakeMP3Copies.hs
https://stackoverflow.com/questions/21715781
复制相似问题