Haskell treats multiple lines of code as one function call
pure :: String -> ()
pure x = unsafePerformIO $ do
print x
return ()
pureCall :: String -> IO ()
pureCall x = do
pure x
putStrLn "inside child function"
This generates a compilation error like,
The function βpureβ is applied to three arguments,
but its type βString -> ()β has only one
I use semicolon as code line separator in other languages. But not sure how I can do this in haskell, and run the pureCall function block as two separate statements!
source to share
Make sure you insert both lines pure
and in the same way putStrLn
(so don't use tabs and others use spaces). If ghc thinks it putStrLn
will backtrack further then it will be considered as arguments pure
.
If you want, you can also use semicolons in Haskell:
pureCall :: String -> IO () pureCall x = do { pure x ; putStrLn "inside child function" }
works as you expected.
(Also note that your code is not very typed: pure
not type-specific IO a
.)
source to share