I expect the following GetArgs.hs
to print out the arguments passed into it.
import System.Environment
main = do
args <- getArgs
print args
But, after loading it in ghci
, I get the following error:
ghci> main 3 4 3
<interactive>:39:1:
Couldn't match expected type `a0 -> a1 -> a2 -> t0'
with actual type `IO ()'
The function `main' is applied to three arguments,
but its type `IO ()' has none
In the expression: main 3 4 3
In an equation for `it': it = main 3 4 3
Since print
has this type:
ghci> :t print print :: Show a => a -> IO ()
I would've expected print args
to have worked.
Why not?
print args
works fine. What doesn't work is main 3 4 3
. main
doesn't take any argument, but you're trying to call it with three.
If you want to simulate calling your program with command line parameters from ghci, you can use the :main
command (with a colon in front). Alternatively you can compile your program and actually run it from the command lines with the given arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With