gpt4 book ai didi

string - Haskell写String,简单题

转载 作者:行者123 更新时间:2023-12-02 07:49:06 25 4
gpt4 key购买 nike

writeStr []=putChar ' '         
writeStr (x:xs) = (putChar x)(writeStr xs)

您好,在此先感谢您,我收到一个类型错误,这应该是一个简单的答案,但我只是不知道错误的来源。

最佳答案

你的代码有点奇怪。如果我做对了,你试着打印一个字符串。您的方法是放置第一个字符串,而不是第二个。但是在 Haskell 中不可能像这样组合两个 IO 操作。再次查看您的教程,它可能看起来像这样:

writeStr []     = return () -- you had putChar ' ',
writeStr (x:xs) = do putChar x -- but this would print a superfluous whtiespace
writeStr xs

如果您想按顺序做几件事,请使用 do 关键字或单子(monad)组合器。很简单,就像这样:

do action1
action2
action3
...

关于string - Haskell写String,简单题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4724853/

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