[Haskell-cafe] replacement

2007-04-14 Thread hossein rohani
Write a function with three parameters, two atoms and a list, (say p1, p2 and L) that returns the list, L, with all occurrences of the first given atom, p1, replaced by the second one, p2. If P2 be nil, the given atom should be deleted and the returned list cannot contain anything in place

Re: [Haskell-cafe] Export Haskell Libraries

2007-04-14 Thread Duncan Coutts
On Thu, 2007-04-12 at 23:38 -0700, SevenThunders wrote: I saw a lot of options for places to put sources and targets, but I couldn't quite figure out how to configure it to place the object file output. No doubt it's there, I just couldn't find it in the 45 min.s or so that I looked for

[Haskell-cafe] Re: k-minima in Haskell

2007-04-14 Thread apfelmus
[EMAIL PROTECTED] wrote: You have n elements, and you need to locate a specific k-element permutation. There are n! / (n-k)! such permutations. You therefore need log(n! / (n-k)!) bits of information. A binary comparison provides one bit of information. So the number of comparisons that

Re: [Haskell-cafe] generate Haskell code from model

2007-04-14 Thread Brian Smith
On 4/14/07, Steffen Mazanek [EMAIL PROTECTED] wrote: Brian, but don't you think that you have to write a lot of boilerplate code in Haskell? I have never felt I was writing a lot of boilerplate. There are a lot of abstraction mechanisms in Haskell to avoid boilerplate. Second, if Haskell

Re: [Haskell-cafe] multithreading speedup

2007-04-14 Thread Fawzi Mohamed
Thanks again to the answers Stefan, Il giorno Apr 14, 2007, alle ore 1:41 AM, Stefan O'Rear ha scritto: On Sat, Apr 14, 2007 at 01:31:58AM +0200, Fawzi Mohamed wrote: Il giorno Apr 14, 2007, alle ore 12:33 AM, Stefan O'Rear ha scritto: On Sat, Apr 14, 2007 at 12:27:10AM +0200, Fawzi

Re: [Haskell-cafe] replacement

2007-04-14 Thread Neil Mitchell
Hi Write a function with three parameters, two atoms and a list, (say p1, p2 and L) that returns the list, L, with all occurrences of the first given atom, p1, replaced by the second one, p2. If P2 be nil, the given atom should be deleted and the returned list cannot contain anything in place

Re: [Haskell-cafe] Re: Translating perl - haskell, string fill ins with an error on invalid inputseems awfullycomplex. Is there a way to simplify?

2007-04-14 Thread Claus Reinke
by utilizing Text.Printf.printf, extracting some more common functionality for the lookups, and changing the error handling (check for errors before giving results, but use throwError instead of error, letting the caller decide whether errors are fatal or not), we arrive at something like:

Re: [Haskell-cafe] multithreading speedup

2007-04-14 Thread Sebastian Sylvan
On 4/14/07, Fawzi Mohamed [EMAIL PROTECTED] wrote: but making my worker threads if I know the number of worker will be more efficient, my program is extremely parallel, but putting a par everywhere would be very memory costly and would probably break the program in the wrong places, I know

Re: [Haskell-cafe] Left-factoring with Parsec

2007-04-14 Thread Claus Reinke
x = x a + b Now use high school algebra x = x*a + b x - x*a = b x*(1-a) = b x = b / (1-a) x = b * 1/(1-a) Now you have to remember that the Taylor series expansion of 1/(1-a) is 1/(1-a) = 1 + a + a^2 + a^3 + a^4 + ... OK, now put your grammar hat back on. What's 1 | a | aa | aaa

Re: [Haskell-cafe] multithreading speedup

2007-04-14 Thread Fawzi Mohamed
Il giorno Apr 14, 2007, alle ore 2:45 PM, Sebastian Sylvan ha scritto: I think you should probably consider the extremely lightweight forkIO threads as your work items and the GHC runtime as your thread pool system (it will find out how many threads you want using the RTS options and

[Haskell-cafe] Do monads imply laziness?

2007-04-14 Thread Brian Hurt
This is probably an off-topic question, but I can't think of a better forum to ask it: does the existance of monads imply laziness in a language, at least at the monadic level? Consider the following: a purely functional, eagerly evaluated programming language, that uses monads to

Re: [Haskell-cafe] Do monads imply laziness?

2007-04-14 Thread Stefan O'Rear
On Sat, Apr 14, 2007 at 10:56:44AM -0400, Brian Hurt wrote: This is probably an off-topic question, but I can't think of a better forum to ask it: does the existance of monads imply laziness in a language, at least at the monadic level? Consider the following: a purely functional,

[Haskell-cafe] Efficient use of ByteString and type classes in template system

2007-04-14 Thread Johan Tibell
Hi Haskell Café! I'm writing a perl/python like string templating system which I plan to release soon: darcs get http://darcs.johantibell.com/template The goal is to provide simple string templating; no inline code, etc.. An alternative to printf and ++. Example usage: import qualified

[Haskell-cafe] Calling C function in Mac OS X

2007-04-14 Thread Sergey Perminov
I wish to optimize Haskell code using ByteString, direct reading Doubles form it, direct writing Doubles to it. I've tried Don Stewart's code http://hpaste.org/26 that uses calling to C functions to implement necessary readDouble showDouble. readDouble works ok. showDouble always return nan in

Re: [Haskell-cafe] Calling C function in Mac OS X

2007-04-14 Thread Stefan O'Rear
On Sat, Apr 14, 2007 at 07:58:25PM +0400, Sergey Perminov wrote: I wish to optimize Haskell code using ByteString, direct reading Doubles form it, direct writing Doubles to it. I've tried Don Stewart's code http://hpaste.org/26 that uses calling to C functions to implement necessary

Re: [Haskell-cafe] Do monads imply laziness?

2007-04-14 Thread Derek Elkins
Brian Hurt wrote: This is probably an off-topic question, but I can't think of a better forum to ask it: does the existance of monads imply laziness in a language, at least at the monadic level? Consider the following: a purely functional, eagerly evaluated programming language, that uses

[Haskell-cafe] LL(1) parsing of declarators

2007-04-14 Thread Stefan O'Rear
I'm writing a code generator for C, and I'm trying to parse a C-like input language using LL(1) (parsec specifically). The syntax of declarators is giving me trouble: (simplified) declaration = qualifiers (declarator `sepBy1` char ',') qualifiers = many1 name declarator = name now if we have

Re: [Haskell-cafe] k-minima in Haskell

2007-04-14 Thread ajb
G'day all. I wrote: O(log(n! / (n-k)!)) = O(n log n - (n-k) log (n-k)) = O(n log (n/(n-k)) + k log (n-k)) That looks right to me. If k n, then this simplifies to O(n + k log n), and if k is close to n, it simplifies to O(n log n + k). Quoting Ian Lynagh [EMAIL PROTECTED]: