[Haskell-beginners] Partial Loading and Debugging with GHCI

Sean Bartell wingedtachikoma at gmail.com
Thu Apr 16 16:33:48 EDT 2009


You can comment out the definition of bad and add a new one:
bad = undefined
The file should load properly. Functions that use "bad" will compile too,
but if they try to evaluate it an error will be raised.

(sorry, forgot to hit "reply to all" the first time)

On Thu, Apr 16, 2009 at 1:34 PM, aditya siram <aditya.siram at gmail.com>wrote:

> Hi all,
> I'm curious as to how one would go about debugging the following program:
>
> hello :: String
> hello = "Hello"
>
> world :: String
> world = "World"
>
> number :: Int
> number = 1
>
> helloWorld :: String
> helloWorld = hello ++ " " ++ world
>
> -- This fails!
> bad :: String
> bad = hello ++ number
>
> Predictably once I load this program into ghci I get the following error:
> [1 of 1] Compiling Main             ( TestCode.hs, interpreted )
>
> TestCode.hs:14:15:
>     Couldn't match expected type `[Char]' against inferred type `Int'
>     In the second argument of `(++)', namely `number'
>     In the expression: hello ++ number
>     In the definition of `bad': bad = hello ++ number
> Failed, modules loaded: none.
>
> At this point what I want to do is to query the output type of the
> different functions like so:
> > :t hello
> but GHCI won't let me because the program hasn't been loaded.
>
> I would then have to comment out 'bad', reload the program and query output
> types to my hearts content. This is fine for a small program, but when I
> have functions are downriver from 'bad', it gets extremely cumbersome. Is
> there a way to load a file such that functions that compile stay loaded in
> the interpreter even if something else fails?
>
> Thanks ...
> -deech
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090416/8e408a7c/attachment-0001.htm


More information about the Beginners mailing list