[Haskell-cafe] how do you debug programs?

2006-09-06 Thread Tamas K Papp
Hi, I would like to learn a reasonable way (ie how others do it) to debug programs in Haskell. Is it possible to see what's going on when a function is evaluated? Eg in f a b = let c = a+b d = a*b in c+d evaluating f 1 2 would output something like f called with values

Re: [Haskell-cafe] how do you debug programs?

2006-09-06 Thread Pepe Iborra
Hi Tamas There are several ways to debug a Haskell program. The most advanced ones are based in offline analysis of traces, I think Hat [1] is the most up-to-date tool for this. There is a Windows port of Hat at [5]. Another approach is to simply use Debug.Trace. A more powerful alternative

Re: [Haskell-cafe] how do you debug programs?

2006-09-06 Thread Donald Bruce Stewart
mnislaih: Hi Tamas There are several ways to debug a Haskell program. The most advanced ones are based in offline analysis of traces, I think Hat [1] is the most up-to-date tool for this. There is a Windows port of Hat at [5]. Another approach is to simply use Debug.Trace. A more

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Tamas K Papp [EMAIL PROTECTED] writes: I would like to learn a reasonable way (ie how others do it) to debug programs in Haskell. Is it possible to see what's going on when a function is evaluated? Eg in f a b = let c = a+b d = a*b in c+d evaluating f 1 2

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Neil Mitchell
Hi But why should c and d exist at runtime? They're only used once each, so the compiler is free to replace f with \a b - (a+b)+ a*b Yes, and if the compiler is this clever, it should also be free to replace them back at debug time. I've said this before, but I think it's worth repeating:

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Lennart Augustsson
I've also used Visual Studio, and I wouldn't mind having something like that for Haskell. But I have to agree with Jon, I think the best way of debugging is to understand your code. I think people who come from imperative programming come with a mind set that you understand your code by

Re: [Haskell-cafe] how do you debug programs?

2006-09-06 Thread Pepe Iborra
Thanks for the suggestion Don, I started the wiki page at http://haskell.org/haskellwiki/Debugging On 06/09/06, Donald Bruce Stewart [EMAIL PROTECTED] wrote: mnislaih: Hi Tamas There are several ways to debug a Haskell program. The most advanced ones are based in offline analysis of

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Tamas K Papp
On Wed, Sep 06, 2006 at 06:33:32AM -0400, Lennart Augustsson wrote: I've also used Visual Studio, and I wouldn't mind having something like that for Haskell. But I have to agree with Jon, I think the best way of debugging is to understand your code. I think people who come from

[Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread Tamas K Papp
Hi, I have a question about coding and compilers. Suppose that a function is invoked with the same parameters inside another function declaration, eg -- this example does nothing particularly meaningless g a b c = let something1 = f a b something2 = externalsomething (f a b) 42

[Haskell-cafe] Re: installing modules

2006-09-06 Thread Stephane Bortzmeyer
On Wed, Sep 06, 2006 at 02:19:14PM +0200, Tamas K Papp [EMAIL PROTECTED] wrote a message of 23 lines which said: Cleanly means that it ends up in the right directory. How do people usually do that? I am using ghc6 on debian testing. Follow the usual cabal routine (everything is in the

Re: [Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread Alex Queiroz
Hallo, On 9/6/06, Tamas K Papp [EMAIL PROTECTED] wrote: PS: I realize that I am asking a lot of newbie questions, and I would like to thank everybody for their patience and elucidating replies. I am a newbie myself (second week of learning Haskell), but I'll give it a shot: Since

[Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Stephane Bortzmeyer
[Warnings: newbie and not having tested or read the generated assembly code.] On Wed, Sep 06, 2006 at 09:32:07AM -0300, Alex Queiroz [EMAIL PROTECTED] wrote a message of 18 lines which said: I am a newbie myself (second week of learning Haskell), but I'll give it a shot: Since functions

Re: [Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Lennart Augustsson
Furthermore, doing that optimization (common subexpression elimination) can lead to space leaks. So you should not count on the compiler doing it. Besides, I often find it more readable and less error prone to name a common subexpression; only one place to change when you need to change

Re: [Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Alex Queiroz
Hallo, On 9/6/06, Lennart Augustsson [EMAIL PROTECTED] wrote: Furthermore, doing that optimization (common subexpression elimination) can lead to space leaks. So you should not count on the compiler doing it. Besides, I often find it more readable and less error prone to name a common

[Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Stephane Bortzmeyer
On Wed, Sep 06, 2006 at 02:12:28PM +0100, Sebastian Sylvan [EMAIL PROTECTED] wrote a message of 36 lines which said: I think most compilers actually do CSE And automatic memoization? Because common subexpressions can be difficult to recognize but, at run-time, it is much easier to recognize

Re: [Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread David Roundy
On Wed, Sep 06, 2006 at 03:26:29PM +0200, Stephane Bortzmeyer wrote: On Wed, Sep 06, 2006 at 02:12:28PM +0100, Sebastian Sylvan [EMAIL PROTECTED] wrote a message of 36 lines which said: I think most compilers actually do CSE And automatic memoization? Because common subexpressions

[Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Sebastian Sylvan
On 9/6/06, Sebastian Sylvan [EMAIL PROTECTED] wrote: On 9/6/06, Stephane Bortzmeyer [EMAIL PROTECTED] wrote: On Wed, Sep 06, 2006 at 02:12:28PM +0100, Sebastian Sylvan [EMAIL PROTECTED] wrote a message of 36 lines which said: I think most compilers actually do CSE And automatic

Re: [Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread Donald Bruce Stewart
tpapp: Hi, I have a question about coding and compilers. Suppose that a function is invoked with the same parameters inside another function declaration, eg -- this example does nothing particularly meaningless g a b c = let something1 = f a b something2 =

[Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Stephane Bortzmeyer
On Wed, Sep 06, 2006 at 09:44:05AM -0400, David Roundy [EMAIL PROTECTED] wrote a message of 33 lines which said: Have you even considered the space costs of this? For almost any non-trivial bit of code I've written, automatic memoization would result in a completely useless binary, as it

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Ketil Malde
Tamas K Papp [EMAIL PROTECTED] writes: Most of the mistakes I make are related to indentation, I use Emacs, which has a reasonably decent mode for this. Hit TAB repeatedly to show the possible indentations. precedence (need to remember that function application binds tightly). It's not

[Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Stefan Monnier
Purely functional does give you some performance benefits, though. Nice theory. People don't use functional languages for their performance, mind you. All the optimizations that are supposedly made possible by having a pure functional language tend to be either not quite doable (because of

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Neil Mitchell [EMAIL PROTECTED] writes: Hi But why should c and d exist at runtime? They're only used once each, so the compiler is free to replace f with \a b - (a+b)+ a*b Yes, and if the compiler is this clever, it should also be free to replace them back at debug time. And

Re: [Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread John Hughes
On 9/6/06, Tamas K Papp [EMAIL PROTECTED] wrote: or does the compiler perform this optimization? More generally, if a function is invoked with the same parameters again (and it doesn't involve anything like monads), does does it makes sense (performancewise) to store the result somewhere?

Re: [Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread Neil Mitchell
Hi All the optimizations that are supposedly made possible by having a pure functional language tend to be either not quite doable (because of non-termination making the language a bit less pure) or simply too hard: the difficulty being to decide when/where the optimization is indeed going to

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Neil Mitchell
Hi Yes, and if the compiler is this clever, it should also be free to replace them back at debug time. And where does that get us? You snipped the salient bit where I said that you'd be debugging a different programme. In Visual C there are two compilation modes. In debug mode, if you

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Tamas K Papp [EMAIL PROTECTED] writes: On Wed, Sep 06, 2006 at 06:33:32AM -0400, Lennart Augustsson wrote: I've also used Visual Studio, and I wouldn't mind having something like that for Haskell. But I have to agree with Jon, I think the best way of debugging is to understand your

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Andrae Muys
On 06/09/2006, at 8:22 PM, Neil Mitchell wrote:It's been my experience that debugging is a serious weakness ofHaskell - where even the poor mans printf debugging changes thesemantics! And everyone comes up with arguments why there is no needto debug a functional language - that sounds more like

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Neil Mitchell [EMAIL PROTECTED] writes: Hi Yes, and if the compiler is this clever, it should also be free to replace them back at debug time. And where does that get us? You snipped the salient bit where I said that you'd be debugging a different programme. In Visual C there

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Neil Mitchell
Hi I think that when it comes to debuggers and Haskell its fairly safe to say: 1) There aren't any which are production quality, regularly work out of the box and are avaiable without much effort. There may be ones which are debuggers (Hat/GHCi breakpoints), but we probably haven't got to the

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Stefan Monnier
I simply can't let this pass without comment. It's irrelevant if you're using a functional or imperative language, debuggers are invariably a waste of time. The only reason to use a debugger is because you need to inspect the contents of a processes address-space; That's a very narrow

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Pepe Iborra
On 06/09/2006, at 17:10, Andrae Muys wrote:On 06/09/2006, at 8:22 PM, Neil Mitchell wrote:It's been my experience that debugging is a serious weakness ofHaskell - where even the poor mans printf debugging changes thesemantics! And everyone comes up with arguments why there is no needto debug a

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Malcolm Wallace
Andrae Muys [EMAIL PROTECTED] wrote: It's a truism to say if your code doesn't work it's because you don't understand it; ... Indeed, but tracing the execution of the code, on the test example where it fails, will often give insight into one's misunderstanding. And often, the person trying

Re: [Haskell-cafe] Re: does the compiler optimize repeated calls?

2006-09-06 Thread David House
On 06/09/06, David Roundy [EMAIL PROTECTED] wrote: Before something like this were to be implemented, I'd rather see automatic strictifying for avoidence of stack overflows (i.e. when the stack starts filling up, start evaluating things strictly), which is most likely another insanely dificult

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jason Dagit
On 9/6/06, Neil Mitchell [EMAIL PROTECTED] wrote: Let take for example a bug I spent tracking down in Haskell this weekend. The bug can be summarized as Program error: pattern match failure: head []. And indeed, thats all you get. A quick grep reveals there are about 60 calls to head in the

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Johan Tibell
Note: I meant to send this to the whole list a couple of messages ago but accidentally I only sent it to Lennart, sorry Lennart! I know that Linus Torvalds doesn't find debuggers all that useful either and he hacks C [1]. 1. http://linuxmafia.com/faq/Kernel/linus-im-a-bastard-speech.html On

Re: [Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread Brian Hulley
John Hughes wrote: The trouble is that this isn't always an optimisation. Try these two programs: powerset [] = [[]] powerset (x:xs) = powerset xs++map (x:) (powerset xs) and powerset [] = [[]] powerset (x:xs) = pxs++map (x:) pxs where pxs = powerset xs Try computing length (powerset

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread David Roundy
On Wed, Sep 06, 2006 at 09:56:17AM -0700, Jason Dagit wrote: Or maybe even more extreme you could use template haskell or the c preprocessor to fill in the line number + column. Which is precisely what darcs does for fromJust (which we use a lot): we define a C preprocessor macro fromJust.

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Chris Kuklewicz
David Roundy wrote: On Wed, Sep 06, 2006 at 09:56:17AM -0700, Jason Dagit wrote: Or maybe even more extreme you could use template haskell or the c preprocessor to fill in the line number + column. Which is precisely what darcs does for fromJust (which we use a lot): we define a C

Re: [Haskell-cafe] getContents and lazy evaluation

2006-09-06 Thread Esa Ilari Vuokko
Hi On 9/6/06, David Roundy [EMAIL PROTECTED] wrote: Fortunately, the undefined behavior in this case is unrelated to the lazy IO. On windows, the removal of the file will fail, while on posix systems there won't be any failure at all. The same behavior would show up if you opened the file for

Re: [Haskell-cafe] does the compiler optimize repeated calls?

2006-09-06 Thread John Hughes
John Hughes wrote: The trouble is that this isn't always an optimisation. Try these two programs: powerset [] = [[]] powerset (x:xs) = powerset xs++map (x:) (powerset xs) and powerset [] = [[]] powerset (x:xs) = pxs++map (x:) pxs where pxs = powerset xs Try computing length (powerset

[Haskell-cafe] Reading integers

2006-09-06 Thread Bertram Felgenhauer
Hi, prompted by a discussion about http://www.spoj.pl/problems/MUL/ on #haskell I implemented some faster routines for reading integers, and managed to produce a program that passes this problem. Currently I have a single module that provides reading operations for Integers and Ints. I'm not

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Neil Mitchell
Hi I don't know what your getout plan was but when I'm in this situation I do the following (hopefully listing this trick will help the OP): I have headNote, fromJustNote, fromJustDefault, lookupJust, lookupJustNote, tailNote - a whole set of functions which take an extra note parameter - or

Re: [Haskell-cafe] Reading integers

2006-09-06 Thread Neil Mitchell
Hi Bertram, Currently I have a single module that provides reading operations for Integers and Ints. I'm not quite sure what to do with it. Get it into base! Where it is, or what its called is less relevant - perhaps entirely decoupled from the Read class, and I wouldn't have thought reading

Re: [Haskell-cafe] Reading integers

2006-09-06 Thread Bertram Felgenhauer
Neil Mitchell wrote: Currently I have a single module that provides reading operations for Integers and Ints. I'm not quite sure what to do with it. Get it into base! Where it is, or what its called is less relevant - Ok, one vote for base. I'm pondering breaking compatibility with Haskell

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Aaron Denney
On 2006-09-06, Andrae Muys [EMAIL PROTECTED] wrote: Jon understates it by implying this is a Functional/Haskell specific quality - it's not. Debuggers stopped being useful the day we finally delegated pointer handling to the compiler/vm author and got on with writing code that actually

Re: [Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Claus Reinke
scientists, who ought to know, assure us that it must be so, oh, let us never, never, doubt, what nobody is sure about. (or something like that..;-) as everyone else in this thread, I have my own experiences and firm opinions on the state of debugging support in Haskell (in particular on the

[Haskell-cafe] head c Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Neil Mitchell [EMAIL PROTECTED] writes: I wrote: H'm. I've never been completely convinced that head should be in the language at all. If you use it, you really have to think, every time you type in the letters h-e-a-d, Am I /really/ /really/ sure the argument will never be []?

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
Claus Reinke [EMAIL PROTECTED] writes: thinking helps, but claiming that tools can't help doesn't. Lets be absolutely clear about this: I've never claimed that tools can't help. In this thread I've been using the term debugger in the narrow sense implied by the OP's question -- something that

[Haskell-cafe] Re: how do you debug programs?

2006-09-06 Thread Jón Fairbairn
David Roundy [EMAIL PROTECTED] writes: On Wed, Sep 06, 2006 at 09:56:17AM -0700, Jason Dagit wrote: Or maybe even more extreme you could use template haskell or the c preprocessor to fill in the line number + column. Which is precisely what darcs does for fromJust (which we use a lot):

[Haskell-cafe] Monad laws

2006-09-06 Thread Deokhwan Kim
What is the practical meaning of monad laws? (M, return, =) is not qualified as a category-theoretical monad, if the following laws are not satisfied: 1. (return x) = f == f x 2. m = return == m 3. (m = f) = g == m (\x - f x = g) But what practical problems can unsatisfying them cause?