String 返回字符串haskell时出错
我试图在Haskell中合并一个字符串,但是我遇到了以下错误,我认为问题在于函数返回fristElem,lastElem merges,但不知道如何修复错误,如何修复错误String 返回字符串haskell时出错,string,haskell,functional-programming,String,Haskell,Functional Programming,我试图在Haskell中合并一个字符串,但是我遇到了以下错误,我认为问题在于函数返回fristElem,lastElem merges,但不知道如何修复错误,如何修复错误 MasterMind.hs:79:98: Couldn't match expected type ‘[Char]’ with actual type ‘[t0] -> [t0]’ Probable cause: ‘fristElem’ is applied to too few argument
MasterMind.hs:79:98:
Couldn't match expected type ‘[Char]’
with actual type ‘[t0] -> [t0]’
Probable cause: ‘fristElem’ is applied to too few arguments
In the second argument of ‘(++)’, namely
‘fristElem (compareShot attempt attempt psw)’
In the second argument of ‘(++)’, namely
‘"\tSeu palpite gero a seguinte dica -> "
++ fristElem (compareShot attempt attempt psw)’
失败,已加载模块:无
使用的代码
compareShot [] _ _ = ""
compareShot (a:attempt) attemptAux psw
|elemIndex a psw == elemIndex a attemptAux = "P" ++ compareShot attempt attemptAux psw
|elemIndex a psw == Nothing = "V" ++ compareShot attempt attemptAux psw
|otherwise = "B" ++ compareShot attempt attemptAux psw
fristElem 0 _ = []
fristElem n (a:xs) = a : fristElem (n-1) xs
lastElem 1 (a:xs) = xs
lastElem n (a:xs) = lastElem (n-1) xs
intercala [] [] = []
intercala (a:xf) (b:xl) = (b:(a:intercala xf xl))`
{-Conta quantas vezes o usuario realizou as tentativas e trata to o fluxo de acerto ou erro-}
attempts :: (Num i, Eq i, Show i) => i -> String -> IO ()
attempts 0 _ = putStrLn "Game Over... !"
attempts i psw = do
putStrLn $ "Entre com o seu palpite ("++ (show i) ++"): (Os digitos do seu palpite devem ser unicos e estar entre 1000 e 9876)"
attempt <- getLine
if validateShot attempt then
if attempt == psw
then putStrLn $ (show attempt) ++ "\nParabens você ganho!"
else do
putStrLn $ (show attempt) ++ "\tSeu palpite gero a seguinte dica -> " ++ fristElem(compareShot attempt attempt psw)
attempts (i-1) psw
else do
putStrLn $ (show attempt) ++ "- Palpite não é valido!"
attempts (i-1) psw
compareShot[]\uuuj=“”
比较shot(a:尝试)尝试辅助psw
|elemIndex a psw==elemIndex a attemptAux=“P”++比较尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试尝试使用psw
|elemIndex a psw==Nothing=“V”++比较hot尝试尝试尝试psw
|否则=“B”++比较hot尝试尝试尝试尝试psw
褶边0=[]
fristElem n(a:xs)=a:fristElem(n-1)xs
lastElem 1(a:xs)=xs
lastElem n(a:xs)=lastElem(n-1)xs
intercala[][]=[]
intercala(a:xf)(b:xl)=(b:(a:intercala xf xl))`
{Conta quantas veves o usuario realize ou as tentiative a e trata o fluxo de acerto ou erro-}
尝试次数::(Num i,Eq i,Show i)=>i->String->IO()
尝试0 u=putStrLn“游戏结束…”
尝试i psw=do
putStrLn$“seu PAPPITE中心”(“++(显示i)++”):(数字seu PAPPITE开发中心1000 e 9876)”
尝试执行以下错误消息:fristElem
(奇怪的名称)接受两个参数,但只获取一个。代码中也清楚地显示了这一点:第一个参数是一个数字(由于省略了签名,很难说它的确切类型),第二个参数是一个列表。在呼叫站点,您只需将compareShot-trument-psw
的结果传递给fristElem
。此外,请尝试将代码减少到说明问题的最小示例。用一种语言(葡萄牙语?)描述的东西太多了,大多数人都听不懂。这是一种写作的尝试吗?不管怎样,一旦修复了编译错误,就开始了解更多您使用fristElem
和lastElem
而不是take
和drop
有什么原因吗?这些都是标准功能,工作得更好。顺便说一句,我认为“猜测”比“尝试”或“射击”更适合于“帕尔皮特”,马萨·法洛·葡萄牙语:-)但是无论如何,欢迎来到这里,很高兴在这里看到来自USP-SC的人;在一个稍有不同的世界里,我本可以在那里获得博士学位(但3年前,哈斯克尔在那里还是个默默无闻的人)。