本文介绍了Shelly:将字符串转换为Shelly FilePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行函数从库到将 a 复制到 b

I need to execute the cp_r function from the Shelly library to copy a to b.

然而, p>

However,

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

for both the first and the second argument to cp_r.

如何使用 String (在任何我知道的平台上都被定义为String) ?

How can I use String (FilePath is defined as String on any platform I know of) as argument to cp_r?

注意:这个问题故意没有显示任何研究工作,因为它被回答为Q& A-Style。

Note: This question intentionally does not show any research effort as it was answered Q&A-Style.

推荐答案

有关详细的官方说明,请参阅。

For a detailed and official description, see the convert between Text and FilePath section on Hackage.

我们先来看看如何通过进行:

Let's first see how to do it with Text:

{-# LANGUAGE OverloadedStrings #-}
import Shelly

cp_r (fromText "a") (fromText "b")

从这里开始,我们可以使用将此方法应用于字符串

From here on, we can just use Text.pack to apply this method to strings

{-# LANGUAGE OverloadedStrings #-}
import Shelly
import Data.Text

cp_r (fromText $ pack "a") (fromText $ pack "b")

请注意,如果您还需要使用前奏曲中的 FilePath / code>在一个模块中,您需要使用

Note that in case you also need to use the FilePath from Prelude in a module, you need to use

import Shelly hiding (FilePath)

避免冲突(或者,您可以使用 Prelude.FilePath Shelly.FilePath )。

to avoid conflicts (alternatively, you could use Prelude.FilePath and Shelly.FilePath).

这篇关于Shelly:将字符串转换为Shelly FilePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:40