gpt4 book ai didi

haskell - 输入 ',' 无法测试两个列表

转载 作者:行者123 更新时间:2023-12-05 00:50:53 24 4
gpt4 key购买 nike

inter :: [Integer] -> [Integer] -> [Integer]
inter s1 s2 = [s | s <- s2, s `elem` s1]

inter [5, 6, 3, 1], [5, 2, 1, 3]

main = return()

我不确定如何测试上述实现,我试图在这里传递两个不同的列表。

我不断收到:

GHCi, version 8.10.6: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/runner/University-Labs/.ghci
[1 of 1] Compiling Main ( Main.hs, interpreted )

Main.hs:4:19: error: parse error on input ‘,’
|
4 | inter [5, 6, 3, 1], [5, 2, 1, 3]
| ^
Failed, no modules loaded.

<interactive>:1:1: error:
• Variable not in scope: main
• Perhaps you meant ‘min’ (imported from Prelude)
 ^C Leaving GHCi.
repl process died unexpectedly:
GHCi, version 8.10.6: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/runner/University-Labs/.ghci


最佳答案

有两件事不对:

  1. 应用多个参数不使用你可以忽略它。

  2. 您不能在文件的顶层使用表达式(如函数应用程序),而是可以将其放在 main 函数中,如下所示:

inter :: [Integer] -> [Integer] -> [Integer]
inter s1 s2 = [s | s <- s2, s `elem` s1]

main = do
print (inter [5, 6, 3, 1] [5, 2, 1, 3])
-- you can do more here if you want

关于haskell - 输入 ',' 无法测试两个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73786958/

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