0
votes

Compiling the code gives

(+++) :: [a] -> [a] -> [a]
lst1 +++ lst2 = if null lst1
                then []
                else (head lst1) : (tail lst1 +++ lst2)


main :: IO ()
main = do
  putStrLn "start"                                                                                                          
  [1,2,3] +++ [4,5,6]
  putStrLn "end"

Couldn't match expected type ‘IO a0’ with actual type ‘[Integer]’ In a stmt of a 'do' block: [1, 2, 3] +++ [4, 5, 6] In the expression: do { putStrLn "start"; [1, 2, ....] +++ [4, 5, ....]; putStrLn "end" } In an equation for ‘main’: main = do { putStrLn "start"; [1, ....] +++ [4, ....]; putStrLn "end" }

What I failed to do anything about - it looks fine to me.

1
You need to print $ [1,2,3] +++ [4,5,6].Aadit M Shah

1 Answers

1
votes

To work off the mismatch error you can simply use the 'print' function. Like that:

(+++) :: [a] -> [a] -> [a]
lst1 +++ lst2 = if null lst1
            then []
            else (head lst1) : (tail lst1 +++ lst2)

main :: IO ()
main = do
   putStrLn "start"                                                                                                          
   print ([1,2,3] +++ [4,5,6])
   putStrLn "end"

Now, I don't know what you want to achieve with the '+++' function, but at least now you don't worry for type errors.

Hope it helped!