Re[2]: [Haskell-cafe] Help with "shootout"

2006-01-03 Thread Bulat Ziganshin
Hello Chris, Tuesday, January 03, 2006, 12:20:26 AM, you wrote: CK> Einar Kartunen sped up the code using a custom channel implementation. CK>This increased speed by a factor of over 2. The wiki at CK> http://haskell.org/hawiki/ChameneosEntry has the latest version. can these channels be

[Haskell-cafe] ST monad

2006-01-03 Thread Bulat Ziganshin
Hello the following code can't go through typechecking. can anyone help me to fix it or, better, let me know what i need to read to fix it myself? :) import Control.Monad.ST import Data.Array.ST main = print $ runST $ do arr <- newArray (1,10) 127 a <- readArray arr 1

RE: [Haskell-cafe] ST monad

2006-01-03 Thread Ralf Lammel
... for the same reason as this one doesn't get through: import Control.Monad.ST import Data.Array.ST main = print $ runST $ do return () ... but this one does: import Control.Monad.ST import Data.Array.ST main = print $ runST ( do return ()) it's all about rank-2 types; s

[Haskell-cafe] ST monad

2006-01-03 Thread oleg
Bulat Ziganshin wrote: the following code can't go through typechecking > import Control.Monad.ST > import Data.Array.ST > main = print $ runST $ >do arr <- newArray (1,10) 127 > a <- readArray arr 1 > writeArray arr 1 216 > b <- readArray arr

Re: [Haskell-cafe] Help with "shootout"

2006-01-03 Thread Chris Kuklewicz
Bulat Ziganshin wrote: > Hello Chris, > > Tuesday, January 03, 2006, 12:20:26 AM, you wrote: > > CK> Einar Kartunen sped up the code using a custom channel implementation. > CK>This increased speed by a factor of over 2. The wiki at > CK> http://haskell.org/hawiki/ChameneosEntry has the la

[Haskell-cafe] file i/o

2006-01-03 Thread Robert Heffernan
Hi, I am relatively new to Haskell and am finding i/o difficult to work with. I am trying to do something like the following: I have a file of data, each line of which looks like this: , INTEGER SEQUENCE for example: FOO ,2,1,4,3,6,7,5,9,10,11,8,13,12, I would like to write a function the read

Re: [Haskell-cafe] file i/o

2006-01-03 Thread Neil Mitchell
Hi Robert, The first thing to mention is that Haskell uses linked-lists, not arrays as the "standard" list type structure, so [1,2] is actually a linked list. The next thing to note is that Haskell is *lazy*. It won't do work that it doens't have to. This means that you can return a linked list w

Re: [Haskell-cafe] Help with "shootout"

2006-01-03 Thread Joel Reymont
It seems like the real difference between TChan and the Ch code below is that TChan is, basically, [TVar a] whereas Ch is MVar [a], plus the order is guaranteed for a TChan. Now why would it matter so much speed-wise? This is the CVS code. newTChanIO is exported but undocumented in GHC 6.4

Re: [Haskell-cafe] Help with "shootout"

2006-01-03 Thread Chris Kuklewicz
[ Deeply nested replies are starting to look similar to runListT $ runStateT $ runWriter ] [EMAIL PROTECTED] wrote: > On Tue, Jan 03, 2006 at 12:07:43AM +, Joel Reymont wrote: > >>On Jan 2, 2006, at 9:20 PM, Chris Kuklewicz wrote: >> >> >>> This makes me ponder one of the things that Joe

Re: [Haskell-cafe] file i/o

2006-01-03 Thread Thomas Davie
The other thing to mention, is that if you have the ability to change file formats, it may be better to make just a slight adjustment... If you make it look exactly like the haskell data structure you want: [("Foo", [1,2,3,4,5,6,7]) ,("Bar", [7,6,5,4,3,2,1]) ,...] Then your parser becomes ev

Re: [Haskell-cafe] Help with "shootout"

2006-01-03 Thread Chris Kuklewicz
Joel Reymont wrote: > It seems like the real difference between TChan and the Ch code below > is that TChan is, basically, [TVar a] whereas Ch is MVar [a], plus the > order is guaranteed for a TChan. > > Now why would it matter so much speed-wise? STM* is usually slower than IO/MVar. STM has t

[Haskell-cafe] Haskell vs. Erlang: Logging to one thread from thousands /Answer/

2006-01-03 Thread Joel Reymont
I asked the Erlang guys why I can log to a single process in Erlang without any problems. The scheduler could well be round-robin but since the message queue is hard-wired to each Erlang process they found an elegant way out. -- There is a small fix in the scheduler for the standard producer/cons

[Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Simon Marlow
Tomasz Zielonka wrote: On Thu, Dec 29, 2005 at 01:20:41PM +, Joel Reymont wrote: Why does it take a fraction of a second for 1 thread to unpickle and several seconds per thread for several threads to do it at the same time? I think this is where the mistery lies. Have you considered a

[Haskell-cafe] Haskell vs. Erlang: The scheduler

2006-01-03 Thread Joel Reymont
On Jan 3, 2006, at 2:30 PM, Simon Marlow wrote: The default context switch interval in GHC is 0.02 seconds, measured in CPU time by default. GHC's scheduler is stricly round- robin, so therefore with 100 threads in the system it can be 2 seconds between a thread being descheduled and schedul

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Simon Marlow <[EMAIL PROTECTED]> wrote: > Tomasz Zielonka wrote: > > On Thu, Dec 29, 2005 at 01:20:41PM +, Joel Reymont wrote: > > > >>Why does it take a fraction of a second for 1 thread to unpickle and > >>several seconds per thread for several threads to do it at the same > >>time

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Chris Kuklewicz
General follow-up questions: Would adding Control.Concurrent.yield commands cause a context switch more often than every 0.02 seconds? Is there any command in GHC to allow a thread to prevent itself from being rescheduled while computing something? Another comment: between 1000's of threads and

[Haskell-cafe] RE: Haskell vs. Erlang: The scheduler

2006-01-03 Thread Simon Marlow
On 03 January 2006 15:13, Joel Reymont wrote: > On Jan 3, 2006, at 2:30 PM, Simon Marlow wrote: >> The default context switch interval in GHC is 0.02 seconds, >> measured in CPU time by default. GHC's scheduler is stricly round- >> robin, so therefore with 100 threads in the system it can be 2 >>

RE: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Simon Marlow
On 03 January 2006 15:37, Sebastian Sylvan wrote: > On 1/3/06, Simon Marlow <[EMAIL PROTECTED]> wrote: >> Tomasz Zielonka wrote: >>> On Thu, Dec 29, 2005 at 01:20:41PM +, Joel Reymont wrote: >>> Why does it take a fraction of a second for 1 thread to unpickle and several seconds per

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Simon Marlow <[EMAIL PROTECTED]> wrote: > On 03 January 2006 15:37, Sebastian Sylvan wrote: > > > On 1/3/06, Simon Marlow <[EMAIL PROTECTED]> wrote: > >> Tomasz Zielonka wrote: > >>> On Thu, Dec 29, 2005 at 01:20:41PM +, Joel Reymont wrote: > >>> > Why does it take a fraction of

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Joel Reymont
Simon, I don't think CPU usage is the issue. An individual thread will take a fraction of a second to deserialize a large packet. The issue is that, as you pointed out, you can get alerts even with 50 threads. Those fractions of a second add up in a certain way that's detrimental to the p

[Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Daniel Carrera
Hello, I've been studying more Haskell and I've improved a lot. But I just hit a small problem. I want to print all the elements of a linst (putStr). I'd like to write something like this: print_list [] = do putStr "" print_list (x:xs) = (do putStr x) && print_list xs I know this is wrong, b

[Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Chris Kuklewicz
Thanks for the answer, but I should I written a longer comment. I have added such a longer comment below: Simon Marlow wrote: > Chris Kuklewicz wrote: > >> Another comment: between 1000's of threads and writing a custom >> continuation based scheduler, what about using a thread pool? Does >> any

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Christian Maeder
Daniel Carrera wrote: print_list xs = do putStr(join xs) where join [] = "" join (x:xs) = (show x) ++ "\n" ++ join xs print_list xs = mapM putStrLn xs Question: What do you call a function that has side-effects? (like putStr) I know that "function" is the wrong term. "action",

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Chris Kuklewicz
Daniel Carrera wrote: > Hello, > > I've been studying more Haskell and I've improved a lot. But I just hit > a small problem. I want to print all the elements of a linst (putStr). > I'd like to write something like this: > > print_list [] = do putStr "" > print_list (x:xs) = (do putStr x) && prin

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Neil Mitchell
Hi, All Haskell functions are lazy, hence there is no need to "write a lazy version" of your print_list function. I think the function you probably want is: putStr (unlines xs) This uses the bulid in unlines function, which is similar in spirit to join (you get more quotes, which I guess you don

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Adrian Hey
On Tuesday 03 Jan 2006 5:37 pm, Christian Maeder wrote: > Daniel Carrera wrote: > > > Question: What do you call a function that has side-effects? (like > > putStr) I know that "function" is the wrong term. > > "action", "command", "program", etc. Actually (at the risk of appearing pedantic), I th

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Daniel Carrera <[EMAIL PROTECTED]> wrote: > Hello, > > I've been studying more Haskell and I've improved a lot. But I just hit > a small problem. I want to print all the elements of a linst (putStr). > I'd like to write something like this: > > print_list [] = do putStr "" > print_list (

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Daniel Carrera
Sebastian Sylvan wrote: Others have already replied with a solution, but it looks to me like what you're "missing" is how to sequence commands, which is the whole purpose of the "do" notation. print_list [] = return () print_list (x:xs) = do putStr x print_list xs The do notation is us

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Daniel Carrera
Chris Kuklewicz wrote: What does lazy printing mean? I assume it means you evaluate the head of the list, print it, then recursively do this for the tail of the list. With an infinite list you will get inifinite output. I assume it does not mean you evaluate the whole list before printing anyt

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Donn Cave
On Tue, 3 Jan 2006, Chris Kuklewicz wrote: ... > I sometimes call a function with side-effects in IO a "command". But > the terms are fungible. But calling putStr a "function" is correct. It > is not a "pure function" however. Is that the standard party line? I mean, we all know its type and s

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Daniel Carrera
Neil Mitchell wrote: All Haskell functions are lazy, hence there is no need to "write a lazy version" of your print_list function. I think the function you probably want is: putStr (unlines xs) Hhmm... that does work, and I'm a bit surprised that it does. I guess I'm still stuck in the eager

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Daniel Carrera <[EMAIL PROTECTED]> wrote: > Neil Mitchell wrote: > > All Haskell functions are lazy, hence there is no need to "write a > > lazy version" of your print_list function. I think the function you > > probably want is: > > > > putStr (unlines xs) > > Hhmm... that does work, an

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Adrian Hey
On Tuesday 03 Jan 2006 6:11 pm, Donn Cave wrote: > On Tue, 3 Jan 2006, Chris Kuklewicz wrote: > ... > > > I sometimes call a function with side-effects in IO a "command". But > > the terms are fungible. But calling putStr a "function" is correct. It > > is not a "pure function" however. > > Is t

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Ezra Cooper
On Jan 3, 2006, at 6:30 PM, Sebastian Sylvan wrote: On 1/3/06, Daniel Carrera <[EMAIL PROTECTED]> wrote: Neil Mitchell wrote: All Haskell functions are lazy, hence there is no need to "write a lazy version" of your print_list function. I think the function you probably want is: putStr (unline

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Cale Gibbard
On 03/01/06, Donn Cave <[EMAIL PROTECTED]> wrote: > On Tue, 3 Jan 2006, Chris Kuklewicz wrote: > ... > > I sometimes call a function with side-effects in IO a "command". But > > the terms are fungible. But calling putStr a "function" is correct. It > > is not a "pure function" however. > > Is th

Re: [Haskell-cafe] Catching string from error function with GHC Control.Exception

2006-01-03 Thread Iain Alexander
I've just been through the process of converting some code from using Control.Exception to using an Error monad, and I would recommend that as a more straightforward and manageable alternative, unless you need Control.Exception for other reasons. I started by changing my potentially-failing fun

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 02:30:53PM +, Simon Marlow wrote: > I measured the time taken to unpickle those large 50k packets as 0.3 > seconds on my amd64 box (program compiled *without* optimisation), so > the thread can get descheduled twice during while unpickling a large > packet, giving a >

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread S. Alexander Jacobson
Joel, In most cases, it just doesn't make sense to run 1000 threads simultaneously that are all bottlenecked on the same resource (e.g. CPU/memory) See e.g. http://www.eecs.harvard.edu/~mdw/proj/seda/ You should be grouping incoming events into queues by expected workload/event. Then you ca

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 05:49:07PM +, Neil Mitchell wrote: > All Haskell functions are lazy, hence there is no need to "write a > lazy version" of your print_list function. I think the function you > probably want is: > > putStr (unlines xs) > > This uses the bulid in unlines function, which

[Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Chris Kuklewicz
Hello, Where there were no entries to the http://shootout.alioth.debian.org/benchmark.php?test=chameneos&lang=all benchmark, there are now two. The one by Josh Goldfoot is already posted, the one Einar Karttunen and I optimized has been submitted and will run faster/smaller. Our code is at htt

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Udo Stenzel
Daniel Carrera wrote: > I've been studying more Haskell and I've improved a lot. But I just hit > a small problem. I want to print all the elements of a linst (putStr). > I'd like to write something like this: > > print_list [] = do putStr "" This looks as if you're confused. The keyword "do"

Re: [Haskell-cafe] file i/o

2006-01-03 Thread Robert Heffernan
Neil and Thomas, Thanks to both of you for your help. I have things working now. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Re: Joels Time Leak

2006-01-03 Thread Joel Reymont
The timeleak code is just a repro case. In real life I'm reading from sockets as opposed to a file. All I'm trying to do is run poker bots. They talk to the server and play poker. Of course some events are more important than others, a request to make a bet is more important than, say, a ta

Re: [Haskell-cafe] RE: Haskell vs. Erlang: The scheduler

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 04:36:37PM -, Simon Marlow wrote: > > Is it impractical then to implement this type of app in Haskell? > > Based on the nature of Haskell scheduling I would be inclined to say > > yes. > > Absolutely not! > > Apart from the problem you have with a space leak caused by

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: > Hello, > > Where there were no entries to the > http://shootout.alioth.debian.org/benchmark.php?test=chameneos&lang=all > benchmark, there are now two. The one by Josh Goldfoot is already > posted, the one Einar Karttunen and I optimized ha

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: > > Hello, > > > > Where there were no entries to the > > http://shootout.alioth.debian.org/benchmark.php?test=chameneos&lang=all > > benchmark, there are now two. The one by Josh Goldf

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Wolfgang Jeltsch
Am Dienstag, 3. Januar 2006 19:15 schrieb Daniel Carrera: > Neil Mitchell wrote: > > All Haskell functions are lazy, hence there is no need to "write a > > lazy version" of your print_list function. I think the function you > > probably want is: > > > > putStr (unlines xs) > > Hhmm... that does wor

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Chris Kuklewicz
Discussing the fannkuch entry Sebastian Sylvan wrote: > On 1/3/06, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > >>On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: >> >>>Hello, >>> >>> And finially, the haskel entry for >>>http://shootout.alioth.debian.org/benchmark.php?test=fannkuch&lang=al

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Cale Gibbard
On 03/01/06, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > On 1/3/06, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > > On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: > > > Hello, > > > > > > Where there were no entries to the > > > http://shootout.alioth.debian.org/benchmark.php?test=chamen

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Cale Gibbard
On 03/01/06, Cale Gibbard <[EMAIL PROTECTED]> wrote: > I managed to do better with the following program which gets the > following time report on my machine > real0m8.175s > user0m7.742s > sys 0m0.186s > as opposed to > real0m23.232s > user0m21.115s > sys 0m0.077s > for the

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Iavor Diatchki
Hello, Here is a short (16 lines) and readable Haskell'98 solution. I haven't optimized it or tested it much. When compiled with ghc(6.4.1) -O2, it takes about 10s to compute the answer for 9, on my P3 366MHz machine. It seems to use about 16K of memory. -Iavor import System(getArgs) flop xs@(x:

[Haskell-cafe] Re: Progress on shootout entries

2006-01-03 Thread Kimberley Burchett
I took a quick crack at optimizing fannkuch.hs. I got it down from 33s to 1.25s on my machine, with N=9. That should put it between forth and ocaml(bytecode) in the shootout page. The main changes I made were using Int instead of Int8, foldl' to accumulate the max number of folds, a custom f

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: > Hello, > > Where there were no entries to the > http://shootout.alioth.debian.org/benchmark.php?test=chameneos&lang=all > benchmark, there are now two. The one by Josh Goldfoot is already > posted, the one Einar Karttunen and I optimized ha

Re: [Haskell-cafe] Project postmortem II /Haskell vs. Erlang/

2006-01-03 Thread Dylan Thurston
On Sun, Jan 01, 2006 at 11:12:31PM +, Joel Reymont wrote: > Simon, > > Please see this post for an extended reply: > > http://wagerlabs.com/articles/2006/01/01/haskell-vs-erlang-reloaded Looking at this code, I wonder if there are better ways to express what you really want using static typi

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Dylan Thurston
On Wed, Jan 04, 2006 at 03:02:29AM +0100, Sebastian Sylvan wrote: > I took a stab at the rev-comp one due to boredom. It's not a space > leak, believe it or not, it's *by design*... > > My god, I think someone is consciously trying to sabotage Haskell's > reputation! > > Instead of reading input

Re: [Haskell-cafe] Progress on shootout entries

2006-01-03 Thread Sebastian Sylvan
On 1/4/06, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > On 1/3/06, Chris Kuklewicz <[EMAIL PROTECTED]> wrote: > > Hello, > > > > Where there were no entries to the > > http://shootout.alioth.debian.org/benchmark.php?test=chameneos&lang=all > > benchmark, there are now two. The one by Josh Goldf

[Haskell-cafe] Re: Progress on shootout entries

2006-01-03 Thread Josh Goldfoot
Keep in mind that the shootout requires that the first 30 permutations printed out by the Fannkuch benchmark to be exactly those given in the "example." Any other order of permutations gets your code labeled "Error" by the shootout administrators. See the discussion here: http://alioth.debian

Re: [Haskell-cafe] Re: Progress on shootout entries

2006-01-03 Thread Jan-Willem Maessen
I was surprised to learn that indexed insertion: permutations (x:xs) = [insertAt n x perms | perms <- permutations xs, n <- [0..length xs] ] insertAt :: Int -> a -> [a] -> [a] insertAt 0 y xs = y:xs insertAt n y (x:xs) = x:(insertAt (n-1) y xs) was faster than the

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 10:28:54PM +0100, Udo Stenzel wrote: > Daniel Carrera wrote: > > print_list [] = do putStr "" > > This looks as if you're confused. The keyword "do" is completely > redundant. "do" does not mean "please ignore all rules and allow side > effects", it rather means "please b

Re: [Haskell-cafe] How to print a string (lazily)

2006-01-03 Thread Glynn Clements
Donn Cave wrote: > > I sometimes call a function with side-effects in IO a "command". But > > the terms are fungible. But calling putStr a "function" is correct. It > > is not a "pure function" however. > > Is that the standard party line? I mean, we all know its type and > semantics, whatev