[Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Keith Wansbrough
I just saw this on the OCaml list (in a posting by Rafael 'Dido' Sevilla [EMAIL PROTECTED] in the Observations on OCaml vs. Haskell thread). I can't believe that a simple wc implementation should be 570 times slower in Haskell than OCaml - could someone investigate and fix the test? --KW 8-)

Re: [Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Malcolm Wallace
Keith Wansbrough [EMAIL PROTECTED] writes: I can't believe that a simple wc implementation should be 570 times slower in Haskell than OCaml - could someone investigate and fix the test? With code like this, I'm not surprised! main = do file - getContents

Re: [Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Tomasz Zielonka
On Tue, Sep 28, 2004 at 10:46:14AM +0100, Keith Wansbrough wrote: I just saw this on the OCaml list (in a posting by Rafael 'Dido' Sevilla [EMAIL PROTECTED] in the Observations on OCaml vs. Haskell thread). I can't believe that a simple wc implementation should be 570 times slower in

Re: [Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Tomasz Zielonka
On Tue, Sep 28, 2004 at 12:01:11PM +0200, Tomasz Zielonka wrote: On Tue, Sep 28, 2004 at 10:46:14AM +0100, Keith Wansbrough wrote: I just saw this on the OCaml list (in a posting by Rafael 'Dido' Sevilla [EMAIL PROTECTED] in the Observations on OCaml vs. Haskell thread). I can't believe

Re: [Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Tomasz Zielonka
On Tue, Sep 28, 2004 at 12:49:52PM +0200, Tomasz Zielonka wrote: On Tue, Sep 28, 2004 at 12:01:11PM +0200, Tomasz Zielonka wrote: On Tue, Sep 28, 2004 at 10:46:14AM +0100, Keith Wansbrough wrote: I just saw this on the OCaml list (in a posting by Rafael 'Dido' Sevilla [EMAIL PROTECTED]

Re: [Haskell-cafe] OCaml list sees abysmal Language Shootout results

2004-09-28 Thread Henning Thielemann
On Tue, 28 Sep 2004, Tomasz Zielonka wrote: Changed readArray to unsafeRead, and it is 47 times faster now. I must say I am pleasantly surprised that GHC managed to unbox everything there was to unbox without much annotations. For 5MB file the program allocated only 192KB in the heap.

[Haskell-cafe] Re: Strings - why [Char] is not nice

2004-09-28 Thread John Goerzen
[ haskell newbie alert ] On 2004-09-20, Henning Thielemann [EMAIL PROTECTED] wrote: On Mon, 20 Sep 2004, Einar Karttunen wrote: Size Handling large amounts of text as haskell strings is currently not possible as the representation (list of chars) is very inefficient. Efficiency is

Re: [Haskell-cafe] Re: Strings - why [Char] is not nice

2004-09-28 Thread MR K P SCHUPKE
Can this not be handled in a nicer way by the compiler? What if the compiler tried to allocate the lists in chunks? For example when dealing with strings, why cant the compiler allocate the string as a fixed length unit, terminated with a link to the next unit. (IE allow the atoms in the list to

[Haskell-cafe] Optmiization of recursion

2004-09-28 Thread John Goerzen
Hello, As I'm investigating Haskell, it's occured to me that most of the Haskell tutorials out there have omitted something that was quite prominent in the OCaml material I had read: making functions properly tail-recursive. The OCaml compiler was able to optimize tail-recursive functions such

Re: [Haskell-cafe] Optmiization of recursion

2004-09-28 Thread Marcin 'Qrczak' Kowalczyk
John Goerzen [EMAIL PROTECTED] writes: The OCaml compiler was able to optimize tail-recursive functions such that they could be compiled using a loop. This would achieve two main benefits: performance due to not needing to allocate/deallocate stack frames, and the ability to work on very

Re: [Haskell-cafe] Optmiization of recursion

2004-09-28 Thread Iavor S. Diatchki
hello, John Goerzen wrote: Hello, As I'm investigating Haskell, it's occured to me that most of the Haskell tutorials out there have omitted something that was quite prominent in the OCaml material I had read: making functions properly tail-recursive. The OCaml compiler was able to optimize

Re: [Haskell-cafe] Optmiization of recursion

2004-09-28 Thread John Goerzen
On Tuesday 28 September 2004 01:54 am, Iavor S. Diatchki wrote: OTOH there are a few classical cases in haskell where you run out of space even if you have a tail recursive function: e.g. sum n [] = n sum n (y:ys) = sum (n + y) ys the reason for this that the n+y expression never gets

Re: [Haskell-cafe] Optimization of recursion

2004-09-28 Thread Georg Martius
Hi, I am also looking for this kind of information in general, however I have done some investigations that answer some of you questions. I posted a question on this kind of optimisation recently [1], but it kept unanswered. On Tue, 28 Sep 2004 18:10:11 + (UTC), John Goerzen [EMAIL

Re: [Haskell-cafe] Optmiization of recursion

2004-09-28 Thread Marcin 'Qrczak' Kowalczyk
John Goerzen [EMAIL PROTECTED] writes: If I instead wrote: sum [] = 0 sum (x:xs) = x + sum(xs) then I have the same problem. What is the proper way to solve this little problem then? sum n [] = n sum n (x:xs) = (sum $! n + x) xs It's unfortunate that it requires $! or seq, but it's

[Haskell-cafe] Silly I/O question

2004-09-28 Thread John Goerzen
I'm trying to write a program that will copy an arbitrarily large text file to a destination, and duplicate it 100 times. Thus: ./myprog Input Output would be the same as running: cat Input Output# once cat Input Output # 99 times My first attempt was this: import IO main = disp

Re: [Haskell-cafe] Optmiization of recursion

2004-09-28 Thread Adrian Hey
On Tuesday 28 Sep 2004 8:17 pm, John Goerzen wrote: On Tuesday 28 September 2004 01:54 am, Iavor S. Diatchki wrote: OTOH there are a few classical cases in haskell where you run out of space even if you have a tail recursive function: e.g. sum n [] = n sum n (y:ys) = sum (n + y) ys

[Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread Peter Simons
John Goerzen writes: That failed, though, because getContents closes the file after it's been completely read (ugh -- why?). getContents reads from standard input: you can't seek on that stream. Just think of cat file | cat. The second invocation reads from a pipe, not from a file on disk.

[Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread John Goerzen
On 2004-09-28, Peter Simons [EMAIL PROTECTED] wrote: John Goerzen writes: That failed, though, because getContents closes the file after it's been completely read (ugh -- why?). You could read the contents once, write it to a temporary file, and then copy it multiple times from there.

Re: [Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread Jon Fairbairn
On 2004-09-28 at 21:19- John Goerzen wrote: On 2004-09-28, Peter Simons [EMAIL PROTECTED] wrote: John Goerzen writes: FWIW, this is working for me: import IO main = disp 100 disp 0 = return () disp n = let copy x = do eof - isEOF if eof

Re: [Haskell-cafe] Optimization of recursion

2004-09-28 Thread Alastair Reid
1. Do Haskell interpreters/compilers perform [tail call optimization]? Georg Martius wrote: ghc does it with one of -O -O1 -O2 switches. hugs doesn't seam to do it since [2] says that foldl (\n _ - n + 1) 0 [1..10] causes a stack overflow. All Haskell compilers (including Hugs)

Re: [Haskell-cafe] GHC and OS X (10.4) [SOLVED]

2004-09-28 Thread Tom Davie
Thanks to a lot of help from Gregory Wright, it is now possible to install ghc 6.2.1 on Tiger - it takes quite a bit of fiddling before it will work, but there is a way. The package available at Haskell.org will not work, however the darwin ports version will given that gcc 3.1 is installed on

Re: [Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread Alastair Reid
On Tuesday 28 September 2004 22:19, John Goerzen wrote: [program that calls isEOF once per line deleted] but it seems wasteful to poll isEOF so much. I think all Haskell implementations have a buffering layer between the Haskell level and the operating system. So, calls to hGetLine, hIsEOF,

[Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread John Goerzen
On 2004-09-28, Alastair Reid [EMAIL PROTECTED] wrote: On Tuesday 28 September 2004 22:19, John Goerzen wrote: That said, if you want to write a cat-like program which is as fast as Unix cat, you should not process data a character at a time or a line at a time but, rather, read fixed size

[Haskell-cafe] Re: Silly I/O question

2004-09-28 Thread karczma
John Goerzen writes: One of the things I do when I learn a new language is to try to probe where its weaknesses are. Please, when meeting new women in your life, don't do so. Otherwise you won't live long enough in order to appreciate your new knowledge... Jerzy Karczmarczuk

[Haskell-cafe] k-th floorRoot

2004-09-28 Thread fool
Hi. floorRootDef, floorRoot :: Integer - Integer - Integer floorRootDef k n | k=1 n=1 = last (takeWhile (\x-x^k=n) [1..]) floorRoot k n | k=1 n=1 = h n where h x = let y=((k-1)*x+n`div`x^(k-1))`div`k in if yx then h y else x (Oddly enough, you get an iteration formula for the _floor_

Re: [Haskell-cafe] Re: Strings - why [Char] is not nice

2004-09-28 Thread ajb
G'day all. Quoting John Goerzen [EMAIL PROTECTED]: * (++) is both a list and a string concatenation operator This could easily be handle by a typeclass. * Pattern matching works well with strings (that's my #1 gripe about strings in OCaml) * Thanks to the laziness of Haskell lists,