Re: [Haskell-cafe] Bit streams programs in Haskell

2006-03-27 Thread Spencer Janssen
I have rewritten the Huffman benchmark (see http://cse.unl.edu/~sjanssen/huffman.hs), resulting in a significant performance increase. On my computer it completes one iteration in about 0.9 seconds. In comparison, the O'Caml version takes around 3.1 seconds. These samples seem to indicate that

Re: [Haskell-cafe] Bit streams programs in Haskell

2006-03-27 Thread Spencer Janssen
It seems I have spoken too soon! There is one infidelity in my implementation: the program writes the output once per iteration, and this IO is included in the measured time. Due to a few changes, this caveat no longer applies. As a result Haskell performs just a bit better. The code is

Re: [Haskell-cafe] Re: Positive integers

2006-03-27 Thread John Meacham
On Fri, Mar 24, 2006 at 06:54:54PM +, Aaron Denney wrote: Without breaking compatibility? But class instances become invalid if the hierarchy is modified. No, compatibility will be broken. Hopefully not for most uses -- I don't think most people define new instances, and those that do

Re: [Haskell-cafe] Positive integers

2006-03-27 Thread Jan-Willem Maessen
On Mar 26, 2006, at 4:35 PM, Daniel McAllansmith wrote: [Discussion of positive integers and Words] I was thinking about several things in this thread, torsors, overflow semantics, bounds checking... I wonder if there would be any merit in being able to define constrained subsets of

Re: [Haskell-cafe] Positive integers

2006-03-27 Thread Burton Samograd
For example, take UNIX nice levels -20 to 19. You could have data ConstrainedInteger = CI {distToMax :: Natural, distToMin :: Natural} this would ensure only the 40 integers can be represented. Then you could have _something_ that defined what happened on overflow, whether it wraps,

Re: [Haskell-cafe] Re: Positive integers

2006-03-27 Thread Dylan Thurston
On Mon, Mar 27, 2006 at 05:02:20AM -0800, John Meacham wrote: well, in interfaces you are going to end up with some specific class or another concretely mentioned in your type signatures, which means you can't interact with code that only knows about the alternate class. like genericLength

Re: [Haskell-cafe] Positive integers

2006-03-27 Thread Neil Mitchell
Doesn't Ada have constrained number types which have similar behaviour? Yes. Just for comparison, the behaviour of the Ada number is to throw an exception at runtime if a number overflows its bounds. If these checks can be eliminated statically, then they are. If an operation will always give a

Re: [Haskell-cafe] Positive integers

2006-03-27 Thread Henning Thielemann
On Mon, 27 Mar 2006, Neil Mitchell wrote: Doesn't Ada have constrained number types which have similar behaviour? Yes. Just for comparison, the behaviour of the Ada number is to throw an exception at runtime if a number overflows its bounds. If these checks can be eliminated statically, then

Re: [Haskell-cafe] Bit streams programs in Haskell

2006-03-27 Thread Per Gustafsson
Hi Thanks to everyone that have helped, the runtimes for the haskell programs have decreased significantly, presently they look like this compared to O'Caml: Benchmark haskell ocaml drop3 5.786 3.151 five11 8.657 7.692 huffman 7.134 18.593 uudecode

Re: [Haskell-cafe] error vs. MonadError vs. fail

2006-03-27 Thread Andrew Pimlott
On Mon, Mar 27, 2006 at 02:53:58PM +1200, Daniel McAllansmith wrote: Is there a consensus on how anticipatable failure situations should be handled? There was a thread, haskell programming guidelines, from 2006-02-25 where John Meacham and Cale Gibbard had a bit of back-and-forth about

[Haskell-cafe] multiple computations, same input

2006-03-27 Thread Greg Fitzgerald
How do I perform multiple computations on a long lazy list without introducing a space leak?Doing a single computation like this works great: f = show . filter ( 1)But if I do something like this: f lst = show (filter ( 1) lst, filter ( 2) lst)then it looks like GHC won't garbage collect list

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Neil Mitchell
Hi Greg, But if I do something like this: f lst = show (filter ( 1) lst, filter ( 2) lst) then it looks like GHC won't garbage collect list elements until the first filter has completely finished There is a very good reason for this, show (a,b) is essentially show (a,b) = ( ++ show a

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Greg Fitzgerald
hold a part of the data in memory while you show the first one,Here would be a better example then. f lst = show (sum (filter ( 1) lst), sum (filter ( 2) lst))It ought to be *possible* to compute both operations without holding onto any of the list elements. In the imperative world, you'd say:

[Haskell-cafe] Defining instance needs allow-undecidable-instance?

2006-03-27 Thread Daniel McAllansmith
Hi, folks. I've got a working class and instances thereof. I would now like to change the class such that error behaviour is specified by MonadError, for the moment throwing String errors. When I try to add MonadError into the types I eventually hit the requirement for

[Haskell-cafe] Re: Equirecursive types?

2006-03-27 Thread lee marks
John Hughes wrote: ... Indeed, error messages in common cases would be worsened significantly, because as Ross says, common errors (such as forgetting a parameter in a recursive call) would lead to legal definitions that cause a type error when applied. Partly for this reason, OCaml

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Neil Mitchell
Hi, Here would be a better example then. f lst = show (sum (filter ( 1) lst), sum (filter ( 2) lst)) I suspected that you actually wanted to do something cleverer with the list, for the sake of argument, I'm going to change 1 to p1 and 2 to p2 - to show how this can be done in the general

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Greg Buchholz
Neil Mitchell wrote: I suspected that you actually wanted to do something cleverer with the list, for the sake of argument, I'm going to change 1 to p1 and 2 to p2 - to show how this can be done in the general case. With the specific information you know about 1 vs 2 you can do better, but

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Greg Fitzgerald
Thanks Neil. How do I add in another ~10 computations, or map a list of a 100 computations to the same input?Isn't there a way to do this without one computation having to be aware of the other? This feels like a situation Parsec users would find themselves in all the time. When you have a bunch

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Neil Mitchell
Thanks Neil. How do I add in another ~10 computations, or map a list of a 100 computations to the same input? Isn't there a way to do this without one computation having to be aware of the other? I guess they have to be aware at some level, perhaps arrows generalise the awareness they need,

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Josef Svenningsson
On 3/28/06, Neil Mitchell [EMAIL PROTECTED] wrote: This feels like a situation Parsec users would find themselves in all the time. When you have a bunch of parsers in a 'choice', does the start of the input stream linger until the last parser is executed? No, as soon as one token is

Re: [Haskell-cafe] Defining instance needs allow-undecidable-instance?

2006-03-27 Thread Daniel McAllansmith
On Tuesday 28 March 2006 11:12, Daniel McAllansmith wrote: Hi, folks. I've got a working class and instances thereof. I would now like to change the class such that error behaviour is specified by MonadError, for the moment throwing String errors. When I try to add MonadError into the types

[Haskell-cafe] Eval of a syntax tree for reduction

2006-03-27 Thread Steve Downey
I'm working through Pierce's Types and Programming Languages on my own. I'm attempting to write the typecheckers in Haskell, instead of ML. However, when it comes to his eval function, I'm a little stuck. The original is let rec eval t = try let t' = eval1 t in eval t' with NoRuleApplies - tWhere

Re: [Haskell-cafe] Eval of a syntax tree for reduction

2006-03-27 Thread Antti-Juhani Kaijanaho
Steve Downey wrote: It makes eval1 a bit more complicated, and not as straightforward translation from the type system being described, though. e.g reducing If looks more like eval1 (TmIfExpr t1 t2 t3) = let t1' = eval1 t1 in case t1' of { Just t1'' - Just $ TmIfExpr t1''

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Tomasz Zielonka
On Mon, Mar 27, 2006 at 03:10:18PM -0800, Greg Fitzgerald wrote: hold a part of the data in memory while you show the first one, Here would be a better example then. f lst = show (sum (filter ( 1) lst), sum (filter ( 2) lst)) It ought to be *possible* to compute both operations

Re: [Haskell-cafe] multiple computations, same input

2006-03-27 Thread Greg Buchholz
Tomasz Zielonka wrote: I wonder if it would be possible to remove the space-leak by running both branches concurrently, and scheduling threads in a way that would minimise the space-leak. I proposed this before http://www.haskell.org/pipermail/haskell-cafe/2005-December/013428.html

Re: [Haskell-cafe] Eval of a syntax tree for reduction

2006-03-27 Thread Greg Buchholz
Steve Downey wrote: ] I'm considering changing eval1 to be ArithExpr-Maybe ArithExpr ] ] If the expression is reducible, then I return Just t, and if it's not ] reducible, then Nothing ] ] It makes eval1 a bit more complicated, and not as straightforward ] translation from the type system being