我是Haskell的新手,正在尝试运行一段代码,但出现此错误: “歧义发生'发现' 它可以引用“ Data.List.find”,从“ Data.List”以sequence.hs:1:1-16导入(最初在“ Data.Foldable”中定义),也可以引用“ Main.find”,在以下位置定义serial.hs:5:1“
import System.IO
import Data.List
find :: String -> FilePath -> IO (Maybe FilePath)
find s d = do
fs <- getDirectoryContents d -- 1
let fs' = sort $ filter (`notElem` [".",".."]) fs -- 2
if any (== s) fs' -- 3
then return (Just (d </> s))
else loop fs' -- 4
where
loop [] = return Nothing -- 5
loop (f:fs) = do
let d' = d </> f -- 6
isdir <- doesDirectoryExist d' -- 7
if isdir
then do r <- find s d' -- 8
case r of
Just _ -> return r -- 9
Nothing -> loop fs -- 10
else loop fs
答案 0 :(得分:3)
假设您从未打算使用此处定义的import Data.List hiding (find)
,则可以将第1行更改为find
。
答案 1 :(得分:2)
根据您的情况,您的选择是:
find
重命名为其他名称。Data.List
导入为合格:import qualified Data.List
。您可以添加as L
来缩短使用Data.List
中内容的代码。