I got a error message from ghc that I didn’t undesrtand, and reduced my code to:
import System.Process
main = do
(_, out, _) <- readProcessWithExitCode "echo" ["foo"]
putStr out
(I should have given an extra argument to readProcessWithExitCode). Compiling that broken program using runghc gives:
Test.hs:4:2:
Couldn't match expected type `IO
(GHC.IO.Exception.ExitCode, String, String)'
against inferred type `(a, b, c)'
In the pattern: (_, out, _)
In a stmt of a 'do' expression:
(_, out, _) <- readProcessWithExitCode "echo" ["foo"]
In the expression:
do { (_, out, _) <- readProcessWithExitCode "echo" ["foo"];
putStr out }
How should I have figured out that I had failed to completely apply a function from this ghc error message?
If you specified a type signature
main :: IO (), the error then becomes:In which case the error is much more obvious.
My guess is that the error isn’t as clear because whilst inferring the type, GHC thinks that you are in the function (i.e.
(a->)) monad rather than IO, in which case you’d be applying the argument afterwards.So don’t be lazy, and include those type signatures! 😉