Skip to content
July 14, 2007 / cdsmith

My Dream GHCi Session

When I use GHCi in my dreams, here’s how it works:

$ ghci MyFile.hs
GHCi, version 9.9.02013010:  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling MyFile              ( MyFile.hs, interpreted )

MyFile.hs:13:5: Not in scope: `callDatabase'

    No instance for (Fractional Integer)

Partially failed, modules loaded: MyFile
MyFile> :t foo
Warning: foo depends on callDatabase, which is not in scope.
Warning: Inferred type may be too general.
foo :: forall a b. (SQL a, SQLData b) => a -> t -> STM [b]

MyFile> :list foo
13: foo sql db = do dat <- callDatabase db sql
14:                 readTVar dat

MyFile> :list 110-114
110:       return [a]
112: bar x = (baz x) / 5
114: {- superCoolFunction: Makes the world end; do not use unless

MyFile> :t baz
baz :: forall a. a -> Integer

MyFile> let bar = fromIntegral (baz x) / 5
MyFile> let callDatabase = undefined :: (SQL a, DBDriver b) => b -> a -> STM TVar
MyFile> :recomp MyFile
[1 of 1] Compiling MyFile              ( MyFile.hs, interpreted )
Ok, modules loaded: MyFile

MyFile> :t foo
foo :: forall a b. (SQL a, DBDriver t, SQLData b) => a -> t -> STM [b]

MyFile> superCoolFunction

And then I wake up! There’s more I’d like to include, such as:

  • Define data structures inside the REPL
  • Ask for the type of an expression *in context* *e.g., what’s the type of 5 in (5 + 3.0)?
  • Change defaulting from the REPL
  • Enter multiline blocks of code without having to edit a file
  • Run code that doesn’t work, and define broken bits = bottom.
  • Show inferred and expected types with :t when type checking fails

But I woke up too soon. (Or, if you prefer, posted this blog entry too soon.)


Leave a Comment
  1. Miguel / Jul 16 2007 1:09 am

    Completely agreed.
    Also: i’d like to see “:t” working for local declarations – something like

    MyFile> :list foo
    foo x = fst $ bar x where bar x = (x,x)
    MyFile> :t foo
    foo :: a -> a
    MyFile> :t foo/bar
    foo/bar :: a -> (a,a)

  2. mnislaih / Jul 17 2007 5:02 am

    :list foo is already working in ghci 6.7. It shouldn’t be very hard to make :list 60-80 work too, if anyone is in for a bit of ghc hacking!

    Local declarations should be hack’able too. Why don’t you propose them for the incoming hackathon ?!

  3. Julian Morrison / Jul 17 2007 8:32 am

    :save — automatically writes your changes into the contextually sensible files. If it’s new, it goes with the package definition if it’s in an already-defined package, or otherwise in a new file. If it’s updated, it goes where it was before. Optional parameters let you directly specify (a) save what (b) where.

  4. xxx / Jul 23 2007 6:06 am

    :doc foo would be cool for showing the documentation


  1. My Dream GHCi Session, Take 2 « Sententia cdsmithus

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: