:main and :run

Contents

The :main and :run commands are for testing command-line applications.

The :main command

The simplest example is :main with no arguments. If you have defined an action called main, then the :main command will run it.

λ> main = putStrLn "Hello!"

λ> :main
Hello!

This may not be very interesting, because this is not any different from what happens if we just asked GHCi to run the main command directly. Notice that we have removed the colon in this second example, so here we not using a GHCi command.

λ> main
Hello!

Arguments

The :main command gets more interesting when we have a program that reads its command-line arguments. A program does this using the following action from the System.Environment System.Environment in base module:

getArgs :: IO [String]

Sign up for access to the full page, plus the complete archive and all the latest content.