Aron Lee
Aron Lee

Reputation: 617

How to run GHCi in command line like a regular shell command

Is there any way I can run GHCi on command line like a regular command in shell?

For example: :browse in GHCi - list all the function for specific module.

but I want to run it on shell, e.g.: ghci --browse "MyModule" which lists all the functions for the module

I know hoogle can run it on shell, e.g: hoogle Monad

Upvotes: 2

Views: 797

Answers (1)

leftaroundabout
leftaroundabout

Reputation: 120751

The easiest way is to pipe in the commands via standard input. In Bash this can be done nicely with a “here-string”:

$ ghci <<< ':t reverse'
GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/sagemuej/.ghci
Loaded GHCi configuration from /home/sagemuej/.ghc/ghci.conf
Prelude> reverse :: [a] -> [a]
Prelude> Leaving GHCi.

Use verbosity 0 to avoid all the greeting stuff:

$ ghci -v0 <<< ':t reverse'
reverse :: [a] -> [a]

Upvotes: 7

Related Questions