inter :: [Integer] -> [Integer] -> [Integer]
inter s1 s2 = [s | s <- s2, s `elem` s1]
inter [5, 6, 3, 1], [5, 2, 1, 3]
main = return()
I am not sure of how to test the above implementation, I am trying to pass two different lists here.
I keep getting:
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
CodePudding user response:
There's two things wrong:
Applying multiple arguments does not use
,
you can just leave that out.You cannot use expressions (like function application) at the top-level in a file, instead you can put it in the
main
function as follows:
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