ghci

ghci displaying execution stack

So I'm working through some initial chapter exercise of Real World Haskell and I wanted to know if there is an option in GHCi to make it show function evaluation with parameters on each recursive call. So for example I wrote a simple version of 'map', and when I apply it, I would like GHCi to display each recursive call with actual argum...

What is GHCi's default implementation of MonadError?

Consider the following test function: testError :: (Error e, MonadError e m) => Bool -> m () testError True = return () testError False = throwError $ strMsg "hello world" At the GHCi prompt, I can do the following: *Main> testError False :: Either String () Left "hello world" *Main> testError True :: Either String () Right () Bec...

ghci configuration file

Hi, I'm using ghci 6.8.2 on Ubuntu. Does ghci use a configuration file where we can do some initial setup?. E.g.: :set prompt "ghci> ". Thanks, Roberto. ...

Prefix form of unary operator in Haskell

In GHCi: Prelude> (+3) 2 5 Prelude> (*3) 2 6 Prelude> (/3) 2 0.6666666666666666 Prelude> (-3) 2 No instance for (Num (t -> t1)) arising from the literal 3' at <interactive>:1:2 Possible fix: add an instance declaration for (Num (t -> t1)) In the expression: 3 In the expression: (- 3) 2 In the definit...

Haskell Error: parse error on input `='

Specs GHC 6.12.1 Mac OS X 10.6.4 x64 MacBook Pro Problem I'm having trouble using let syntax. The following code refuses to compile: module Main where main = let x = 1 y = 2 z = 3 in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z I tried tabbing in y = 2 and z = 3 even more. No dice. ...

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> ...

Multiple source files in Haskell

I'm writing my first big project in Haskell and I'd like to split it across multiple files. So far, I have written two modules, Parse and Eval. I'd like to have a Main module that just includes these two modules and specifies the main function. I have the files Main.hs, Parse.hs, and Eval.hs and import them in Main, but this happens: Pr...

head and tail calls on empty list bringing an exception

I'm following a tutorial. (Real World Haskell) And I have one beginner question about head and tail called on empty lists: In GHCi it returns exception. Intuitively I think I would say they both should return an empty list. Could you correct me ? Why not ? (as far as I remember in OzML left or right of an empty list returns nil) I sur...

Is there a way to limit the memory, ghci can have?

I'm used to debug my code using ghci. Often, something like this happens (not so obvious, of course): ghci> let f@(_:x) = 0:1:zipWith(+)f x ghci> length f Then, nothing happens for some time, and if I don't react fast enough, ghci has eaten maybe 2 GB of RAM, causing my system to freeze. If it's too late, the only way to solve this pr...

GHCi usage question

I am studying Haskell and use Emacs+Haskell mode as my editor. After playing some simple expressions in GHCi, I am wondering whether these IDE/editor functionality that exist in Visual Stuido for F#: Can I send the content in the clipboard into the interpreter? Currently I can only :load the file into the interpreter. This is inconv...

Is it possible to define new ADTs in GHCi

While commenting on new features in ghci I wished that ghci had the ability to declare type declaration and declaring new ADT types, someone informed that it was indeed possible, and after searching I found this page which told me I could do let numUniques' :: (Eq a) => [a] -> Int; numUniques' = length . nub Apparently that same sort...

Specifying package name for module-related commands in ghci

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 ...

Saving my running toplevel for later

Hi, When working in the ocaml or ghci toplevels I often build up a significant "context" for want of a better word, values bound, functions, modules loaded, and so on. Is there a way to save all of that and reload it later so I can continue exactly where I left off? Or better yet, dump out the entire lot as a text file that could be rel...