Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Roman Cheplyaka
* Haisheng Wu fre...@gmail.com [2012-02-05 14:28:10+0800] a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] Do you have any cool solution in FP way? You can use IntMap as a replacement for arrays: (I didn't understand your

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Jon Fairbairn
Haisheng Wu fre...@gmail.com writes: a = [1,1,1,1] b = [0,1,2,3] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] Do you have any cool solution in FP way? I find the above sufficiently alien that I can’t work out what it’s meant to do (what is it actually

[Haskell-cafe] Fwd: Rewrite this imperative in FP way

2012-02-05 Thread L Corbijn
-- Forwarded message -- From: L Corbijn aspergesoe...@gmail.com Date: Sun, Feb 5, 2012 at 10:07 AM Subject: Re: [Haskell-cafe] Rewrite this imperative in FP way To: Haisheng Wu fre...@gmail.com On Sun, Feb 5, 2012 at 7:28 AM, Haisheng Wu fre...@gmail.com wrote: a = [1,1,1,1] b

Re: [Haskell-cafe] ANN: combinatorics

2012-02-05 Thread Daniel Fischer
On Wednesday 01 February 2012, 07:53:03, wren ng thornton wrote: The primes function in the combinat package is based on an old Cafe thread, and actually seems to be faster than the one in the combinatorics package. Yes, but it has a memory leak. On my box at least, with ghc 6.12, 7.0 and

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Haisheng Wu
Sorry there is a mistake in the problem description. Here it is in Python: a = [1,1,1,1] b = [0,1,2,3] c = [0,2] d = [0,0,0,0] for i in b: for j in c: if (i+j)3: d[i+j] += a[i] -Haisheng On Sun, Feb 5, 2012 at 2:28 PM, Haisheng Wu fre...@gmail.com wrote: a =

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Yves Parès
Concerning your first solution, I don't understand why you redefine Eq but not Ord instance. Ord will still work by comparing the tuples and not the first elements of said tuples. Plus the good news is you don't have to do this: just use regular tuples and use sort*By *or group*By *functions from

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Yves Parès
For instance your Eq instance could have been written x == y = (==) `on` (fst . getTuple) Sorry, wrong arity: (==) = (==) `on` (fst . getTuple) Okay for the imperative code. 2012/2/5 Yves Parès yves.pa...@gmail.com Concerning your first solution, I don't understand why you redefine Eq but

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Morel Pisum
+= a[i] is the same as +=1, isn't it? (i accidentally didn't reply to the list on my first try. sorry.) Am 05.02.2012 16:36, schrieb Haisheng Wu: Sorry there is a mistake in the problem description. Here it is in Python: a = [1,1,1,1] b = [0,1,2,3] c = [0,2] d = [0,0,0,0] for i in b:

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Mike Burns
Can you write it as a Python function? Another way of asking: is the goal to mutate d or is it to produce the list? On 2012-02-05 23.36.28 +0800, Haisheng Wu wrote: Sorry there is a mistake in the problem description. Here it is in Python: a = [1,1,1,1] b = [0,1,2,3] c = [0,2] d =

Re: [Haskell-cafe] Rewrite this imperative in FP way

2012-02-05 Thread Matthew Farkas-Dyck
On Sun, Feb 5, 2012 at 2:28 PM, Haisheng Wu fre...@gmail.com wrote: for i in b: for j in c: if (i+j)3: d[i+j] += a[i] Do you have any cool solution in FP way? Not sure whether this is cool, but here it is nonetheless: a = repeat 1; b = [0..3]; c = [0,2]; d = map (sum ∘ map ((a

[Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Michael Rice
Stack space overflow: current size 8388608 bytes. Use `+RTS -Ksize -RTS' to increase it. == Couldn't find much on the man or info pages. Example please, say double it (1600) for starters. Michael ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Mathijs Kwik
./myProgram +RTS -K1600 If that gives an error, you're program was probably compiled without support for setting RTS options from the command line. Recompile with -rtsopts. Then the above should work On Sun, Feb 5, 2012 at 8:16 PM, Michael Rice limitc...@gmail.com wrote: Stack space

Re: [Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Michael Rice
I'm using ghc --make... -rtsopts seems to be a link directive. The GHC docs seem to be project oriented. What's the two step process to compile and link a simple .hs file? ghc source.hs (to compile) link step? Michael On Sun, Feb 5, 2012 at 2:21 PM, Mathijs Kwik

Re: [Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Krzysztof Skrzętnicki
No, you supply -rtsopts along with --make. Actually --make is just a shorthand for a few other options, you can see which with --verbose. See the documentation too. One important thing though: very often stack overflows come from bad code. See the wiki for more info:

Re: [Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Michael Rice
I had tried -rtsopts in a few spots in the command line, both with and without --make, seemingly with no effect . There was indeed a code problem, a function applied to an expression that should have been in parens. Shoulda known better. Thanks, all. Michael 2012/2/5 Krzysztof Skrzętnicki

[Haskell-cafe] ANN: exists-0.1

2012-02-05 Thread Gábor Lehel
There's a common pattern in Haskell of writing: data E where E :: C a = a - E also written data E = forall a. C a = E a I recently uploaded a package to Hackage which uses the new ConstraintKinds extension to factor this pattern out into an Exists type parameterized on the constraint, and also

Re: [Haskell-cafe] ANN: combinatorics

2012-02-05 Thread wren ng thornton
On 2/5/12 10:21 AM, Daniel Fischer wrote: Why not use one of the packages on hackage which offer faster prime generators? Mostly because I hadn't looked, having had the code already laying around. I'm not opposed to it, however another goal is to remain portable to other compilers, which

[Haskell-cafe] ANNOUNCE: system-filepath 0.4.5 and system-fileio 0.3.4

2012-02-05 Thread John Millikin
Both packages now have much-improved support for non-UTF8 paths on POSIX systems. There are no significant changes to Windows support in this release. system-filepath 0.4.5: Hackage: http://hackage.haskell.org/package/system-filepath-0.4.5 API reference:

Re: [Haskell-cafe] ANN: combinatorics

2012-02-05 Thread Daniel Fischer
On Sunday 05 February 2012, 23:14:35, wren ng thornton wrote: On 2/5/12 10:21 AM, Daniel Fischer wrote: Why not use one of the packages on hackage which offer faster prime generators? Mostly because I hadn't looked, having had the code already laying around. Yeah, that's fine, it was

[Haskell-cafe] ANN: Updated OpenGL libraries

2012-02-05 Thread Jason Dagit
Hello, I'm pleased to anounce a minor bug fix release of the OpenGL libraries. This release was prompted by issues and warnings when compiling with ghc-7.4.1. The following packages have been updated: * OpenGLRaw 1.2.0.0 * OpenGL 2.5.0.0 * GLURaw 1.2.0.0 * GLUT 2.3.0.0 Thanks goes out

Re: [Haskell-cafe] ANN: combinatorics

2012-02-05 Thread wren ng thornton
On 2/5/12 5:40 PM, Daniel Fischer wrote: On Sunday 05 February 2012, 23:14:35, wren ng thornton wrote: On 2/5/12 10:21 AM, Daniel Fischer wrote: Why not use one of the packages on hackage which offer faster prime generators? Mostly because I hadn't looked, having had the code already laying

Re: [Haskell-cafe] ANN: exists-0.1

2012-02-05 Thread Yves Parès
That is a great initiative. I didn't know about those Kind extensions that enable you to pass a typeclass as a type parameter... However, have you considered putting the Data.Exists.Default module in a separate package? That would reduce the dependencies for those who just need Exists and

[Haskell-cafe] Greetings and Maybe GSoC-2012

2012-02-05 Thread Sergiu Ivanov
Hello everyone, (long mail ahead) My name is Sergiu Ivanov, I have been trying to wrap my mind around Haskell for 2 years already, but success still feels far away :-) This makes me more and more attached to Haskell though, so I can plainly say: I love this language :-) I guess I should have

Re: [Haskell-cafe] ANNOUNCE: system-filepath 0.4.5 and system-fileio 0.3.4

2012-02-05 Thread Joey Hess
John Millikin wrote: In GHC 7.2 and later, file path handling in the platform libraries was changed to treat all paths as text (encoded according to locale). This does not work well on POSIX systems, because POSIX paths are byte sequences. There is no guarantee that any particular path will

Re: [Haskell-cafe] ANNOUNCE: system-filepath 0.4.5 and system-fileio 0.3.4

2012-02-05 Thread John Millikin
On Sun, Feb 5, 2012 at 18:49, Joey Hess j...@kitenet.net wrote: John Millikin wrote: In GHC  7.2 and later, file path handling in the platform libraries was changed to treat all paths as text (encoded according to locale). This does not work well on POSIX systems, because POSIX paths are byte

Re: [Haskell-cafe] ANNOUNCE: system-filepath 0.4.5 and system-fileio 0.3.4

2012-02-05 Thread John Millikin
On Sun, Feb 5, 2012 at 19:17, John Millikin jmilli...@gmail.com wrote: -- $ ~/ghc-7.0.4/bin/ghci Prelude writeFile .txt test Prelude readFile .txt test Prelude Sorry, that got a bit mangled in the email. Corrected