Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying package name for module-related commands in ghci

Tags:

Is there a way to specify the package name for a module for the :browse, :load or :module commands in ghci (version 6.12.1) ?

Some module names are ambiguous:

Prelude> :module Control.Monad.Cont  <no location info>:     Ambiguous module name `Control.Monad.Cont':       it was found in multiple packages: mtl-1.1.0.2 monads-fd-0.1.0.2 

Is setting the -hide-package option the only thing I can do to avoid the ambiguity?

like image 835
gawi Avatar asked Oct 12 '10 20:10

gawi


People also ask

How do I import a package into Haskell?

The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.

How do you define a function in GHCi?

Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!

Where are Haskell packages installed?

If you don't need a fully partitioned GHC environment and are happy with the installed versions on DICE, cabal might be the simplest way to install the Haskell packages you require. By default stack installs packages to ~/. cabal and ~/. ghc in your home directory.

How do I run a program in GHCi?

Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)


1 Answers

As far as I know, yes. But it doesn't have to be a big deal, you can do this inside ghci:

Prelude Data.List> :set -hide-package mtl package flags have changed, resetting and loading new packages... Prelude> import Control.Monad.Cont Prelude Control.Monad.Cont>  

There was also a line-item on GHC-7 change log that made me think package imports would work on the command line, but it doesn't seem to yet (see below). The change comment said something like "full import syntax supported in GHCi", which must exclude extensions I suppose.

$ ghci-7.0.0.20100924 -XPackageImports GHCi, version 7.0.0.20100924: http://www.haskell.org/ghc/  :? for help ... Prelude Data.List> import "mtl" Control.Monad.Cont  <no location info>:     Ambiguous module name `Control.Monad.Cont':       it was found in multiple packages: mtl-1.1.1.0 monads-fd-0.1.0.2 
like image 179
Thomas M. DuBuisson Avatar answered Sep 27 '22 21:09

Thomas M. DuBuisson