gpt4 book ai didi

haskell - 如何写 return Haskell

转载 作者:行者123 更新时间:2023-12-03 00:48:47 24 4
gpt4 key购买 nike

我希望我的 showStackHead 函数采用堆栈打印头部并返回其余部分,这是我的代码--代码

showStackHead xx
| xx == [] = return []
| otherwise = do putStrLn("result:" ++ (head xx))
return (tail xx)

当我运行这段代码时,编译器告诉我第二次返回存在解析错误,那么编写此函数的正确方法是什么?

最佳答案

将“return”缩进到与“putStrLn”相同的深度,如下所示:

showStackHead xs
| xs == [] = return []
| otherwise = do putStrLn ("result:" ++ (head xs))
return (tail xs)

关于haskell - 如何写 return Haskell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3130177/

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