How to exit the "Main" status after Prelude(Haskell) loaded a module?

6.2k views Asked by At

In Haskell, after using Prelude to load some files

Prelude> :l xxxFileName

The prompt beomes

*Main> xxxx

I don't know where the "Main" function come from, as I didn't define any function called "Main". Is this a special status of Haskell's command line environment? How can I exit the "*Main" prompt context and come back to "Prelude>"?

Thanks.

1

There are 1 answers

1
Zeta On

That's a GHCi convention. By default, GHCi will show the name of the module you've loaded. An asterisk (*) indicates that you have access on all top-level bindings (definitions that aren't inside of other ones), and not the ones that are exported.

If you didn't specify a module name in the file, GHCi will assume its name is Main:

-- Example.hs
add x y = x + y
Prelude> :l Example.hs
*Main>

However, if you do specify a module name, GHCi will display that one instead:

-- ProperModule.hs
module ProperModule where

add x y = x + y
Prelude> :l ProperModule.hs
*ProperModule>

To unload any additional modules, use :m, but keep in mind that you cannot use functions from xxxFileName.hs anymore. Note that Prelude is always loaded, unless you've started GHCi with -XNoImplicitPrelude.