Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

haskell - How to configure GHCi to automatically import modules

When I use GHCi, I almost always end up importing Control.Applicative, Data.List, etc. . Is there a way to configure GHCi to automatically import those modules.

Also, after importing them, how do I keep the prompt from being insanely long?

Prelude Control.Applicative Data.List Database.HDBC Database.HDBC.Sqlite3 System.Directory>
question from:https://stackoverflow.com/questions/3518619/how-to-configure-ghci-to-automatically-import-modules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

GHCi looks for its configuration file at

  • ~/.ghc/ghci.conf on Unix-like systems.

  • %APPDATA%ghcghci.conf on Windows.

The configuration file syntax is simple: it's a list of GHCi commands to execute on startup.

For example, your ghci.conf could contain:

import Control.Applicative
import Data.Char
import Data.List

:set prompt "> "

The last line sets the prompt to "> " so it won't show all the modules you imported on the command line.

Now you can get to work right away:

GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
> toLower <$> "Hello, world!"
"hello, world!"
> 

Also, if you decide you don't want Data.Char in the middle of a GHCi session, you can remove it with:

:m -Data.Char

and if you decide you don't want anything but Prelude during a session:

:m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...