Skip to content

Instantly share code, notes, and snippets.

@laser
Last active August 29, 2015 14:07
Show Gist options
  • Save laser/789b4416a0aa55bafd72 to your computer and use it in GitHub Desktop.
Save laser/789b4416a0aa55bafd72 to your computer and use it in GitHub Desktop.
Basic GHCI Commands

Running the REPL (GHCI)

~/dev> ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
:Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... tlinking ... done.
Prelude>

Obtaining the Types of Things

Simply enter :type followed by a name:

Prelude> :type map
map :: (a -> b) -> [a] -> [b]

You can also get the types of partially-applied functions:

Prelude> :type map show
map show :: Show a => [a] -> [String]

Obtaining Information About Classes, Constructors, and Other Things

Use the :info command:

Prelude> :info Num
class Num a where
  (+) :: a -> a -> a
  (*) :: a -> a -> a
  (-) :: a -> a -> a
  negate :: a -> a
  abs :: a -> a
  signum :: a -> a
  fromInteger :: Integer -> a
  	-- Defined in `GHC.Num'
instance Num Integer -- Defined in `GHC.Num'
instance Num Int -- Defined in `GHC.Num'
instance Num Float -- Defined in `GHC.Float'
instance Num Double -- Defined in `GHC.Float'

Loading Files

Loading a file can be achieved using the :load command. Path is relative to where you started GHCI.

Prelude> :l src/Cis194/Hw/Week1.hs
[1 of 1] Compiling Cis194.Hw.Week1  ( src/Cis194/Hw/Week1.hs, interpreted )
Ok, modules loaded: Cis194.Hw.Week1.
*Cis194.Hw.Week1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment