gpt4 book ai didi

Haskell:无法将类型 ‘[Char]’ 与 ‘Text’ 匹配

转载 作者:行者123 更新时间:2023-12-02 15:08:09 25 4
gpt4 key购买 nike

出于某种原因 - 我希望通过提出这个问题来找出原因 - 最近对 haskell 脚本实现了一系列更新,包括添加:

import System.Directory (doesFileExist, removeFile,getPermissions)

用于促进以下功能:

validFile :: FilePath -> IO Bool
validFile path = do
exists <- (doesFileExist path)
if exists
then (readable <$> getPermissions path)
else return False

调用为:

pwds <- case cfgPasswords of
Just passPath -> do
pathChecksOut <- validFile passPath
when (not pathChecksOut) $
errorL' ("Failed to access file at : " ++ passPath)
(map (Just . T.unpack) . lines) <$> readFileUtf8 passPath
Nothing -> return $ replicate (length cfgPublicKeys) Nothing

我无法再在我的机器上构建项目。

我得到的错误是Couldn't match type ‘[Char]’ with ‘Text’,它指向我以下行:

errorL'(“访问文件失败:”++ passPath)

似乎有一个关于 StackOverflow 的问题试图解决类似的问题,this one .为了遵循该建议,我像这样调整了行 errorL' ("Failed to access file at : "++ (passPath::Text)),但我仍然无法构建该项目。

在实现您在上一篇文章中推荐的更改后,我收到的确切控制台输出如下所示:

enter image description here

完整的文件和添加此功能的进度(而不是错误!)被很好地封装在this gist file 中。 .

最佳答案

String 转换(这就是 FilePath 是)到 Text您需要明确使用 pack : 单独的类型注释是不行的。

您还需要使用 append (或 Monoid(<>) )而不是 (++)这是特定于列表的。

关于Haskell:无法将类型 ‘[Char]’ 与 ‘Text’ 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45920385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com