Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Alex Jacobson
The challenge was the implement the modcount algorithm not to calculate primes per se. (see e.g. http://jjinux.blogspot.com/2005/11/io-comparison.html). -Alex- Donald Bruce Stewart wrote: alex: This implementation of calculating 1 primes (compiled with GHC -O2) is 25% slower than the

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Alex Jacobson
Thought perhaps the problem is that modcount is just a slower algorithm. ... nevermind. Thanks. -Alex- Alex Jacobson wrote: The challenge was the implement the modcount algorithm not to calculate primes per se. (see e.g. http://jjinux.blogspot.com/2005/11/io-comparison.html). -Alex-

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Paulo Tanimoto
Alex: The challenge was the implement the modcount algorithm not to calculate primes per se. (see e.g. http://jjinux.blogspot.com/2005/11/io-comparison.html). Can you show us the Python code? Paulo ___ Haskell-Cafe mailing list

[Haskell-cafe] Re: creating graphics the functional way

2007-08-06 Thread apfelmus
Frank Buss wrote: I've created a small program to compose images with combinators: http://www.frank-buss.de/haskell/OlympicRings.hs.txt Finally, what do you think about using this concept for generating images? It has some advantages, e.g. it is possible to scale the image without quality

[Haskell-cafe] Re: Navigating Haddock

2007-08-06 Thread apfelmus
Marc Weber wrote: On Sun, Aug 05, 2007 at 03:19:25PM -0700, David Pollak wrote: Howdy, As I'm starting to learn the Haskell libraries, I'm having a less than fun time trying to figure out what functions operate on what types. For example, in the documentation for HaXml, there's a

[Haskell-cafe] Re: creating graphics the functional way

2007-08-06 Thread Shin-Cheng Mu
On 05/08/07, Frank Buss [EMAIL PROTECTED] wrote: Is it possible to write functions with an arbitrary number of arguments? Would be nice if the average function would accept any number of pixel values. You may be interested to see Oleg Kiselyov's discussion on polyvariadic functions in

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Vimal
Why not just: primes = sieve [2..] sieve (p : xs) = p : sieve [x | x - xs, x `mod` p 0] main = print (take 1000 primes) I am unable to see how exactly this will run. Given that primes is an infinite list, and that when it reaches numbers say, as large as

Re: [Haskell-cafe] Perfect example

2007-08-06 Thread Hugh Perkins
There's a neat Haskell solution to the knapsack problem which runs very fast. I'm not 100% sure that it runs faster than an optimal solution in other GC'd imperative languages, but it's very concise and not (too) convoluted. Have a search for the thread with xkcd in the title. Chung-chieh Shan

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread david48
On 8/6/07, Vimal [EMAIL PROTECTED] wrote: I am unable to see how exactly this will run. Given that primes is an infinite list, and that when it reaches numbers say, as large as 1, it will have to keep track of all the numbers (essentially prime numbers, which is the answer), whose

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Vimal
Isn't it how it runs ? : 2: sieve [3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45, 47,49,... ] then 2:3:sieve [5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,... ] then 2:3:5:sieve [7,11,13,17,19,23,29,31,37,41,43,47,49,... ] then 2:3:5:7:sieve

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Vimal
primes n = sieve (take n [2..]) sieve (p:xs) = p : sieve [x | x - xs, x `mod` p 0] print (primes 1000) -- Vimal But as we can see, this obviously doesn't *take* 1000 primes, :-) -- Vimal ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] c2hs and structs?

2007-08-06 Thread Duncan Coutts
On Sat, 2007-08-04 at 23:59 +0100, Magnus Therning wrote: I can't seem to find any information on how to deal with C functions that return a (pointer to a) struct. C2hs tells me there's no automatic support for marshalling structs (I'm using version 0.14.5). If I'm to do it by hand, is

Re: [Haskell-cafe] Re: Navigating Haddock

2007-08-06 Thread Neil Mitchell
Hi a) use hoogle (haskell.org/hoogle). You can use hoogle to find functions by types. But I don't know haw to create a query such as ... - Document - ... Hoogle unfortunately doesn't do that very well, although that would be a great feature. Wait for version 4 :-) - I've added _ 's for

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Janis Voigtlaender
Vimal wrote: Why not just: primes = sieve [2..] sieve (p : xs) = p : sieve [x | x - xs, x `mod` p 0] main = print (take 1000 primes) I am unable to see how exactly this will run. Given that primes is an infinite list, and that when it reaches numbers say, as

Re: [Haskell-cafe] how to make haskell faster than python at finding primes?

2007-08-06 Thread Alex Jacobson
Paulo Tanimoto wrote: The challenge was the implement the modcount algorithm not to calculate primes per se. (see e.g. http://jjinux.blogspot.com/2005/11/io-comparison.html). Can you show us the Python code? Note this is python for the naive, accumulate and do modulus version. Not for

[Haskell-cafe] Sudoku Solver

2007-08-06 Thread Adrian Neumann
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Hi, I wrote a brute-force sudoku solver. It takes a [[Int]] and spits out the first solution it finds. Why is it, that [0,0,0,7,0,6,9,0,0] [9,0,0,0,0,4,7,0,0] [7,0,0,0,0,0,4,0,0] [0,2,7,0,3,5,8,0,0] [6,9,5,8,2,0,0,0,0] [0,8,0,0,0,0,5,0,0]

[Haskell-cafe] Re: Zippers, Random Numbers Terrain

2007-08-06 Thread apfelmus
Thomas Conway wrote: On 8/2/07, apfelmus [EMAIL PROTECTED] wrote: That concludes the infinite terrain generation for one dimension. For higher dimension, one just needs to use 2D objects instead of intervals to split into two or more pieces. For instance, one can divide equilateral triangles

[Haskell-cafe] ICFP07 Call for Participation

2007-08-06 Thread Matthew Fluet (ICFP Publicity Chair)
= Call for Participation The 12th ACM SIGPLAN International Conference on Functional Programming (ICFP 2007) http://www.informatik.uni-bonn.de/~ralf/icfp07.html

[Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread peterv
In de book Modern C++ design, Andrei Alexandrescu writes that Haskell supports “multi-methods” http://books.google.com/books?id=aJ1av7UFBPwCpg=PA3ots=YPiJ_nWi6Ydq=moder n+C%2B%2Bsig=FWO6SVfIrgtCWifj9yYHj3bnplQ#PPA263,M1 How is this actually done in Haskell? Maybe this is just a basic feature of

[Haskell-cafe] [Fwd: PADL 2008: Call for Papers]

2007-08-06 Thread Paul Hudak
Original Message Subject:PADL 2008: Call for Papers Date: Sat, 4 Aug 2007 19:25:58 -0500 (CDT) From: Gopal Gupta [EMAIL PROTECTED] [ Colleagues, note that this will be the 10th PADL; We strongly urge you to submit papers, the deadline is only 3 weeks way]

Re: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread Brian Hulley
peterv wrote: In de book Modern C++ design, Andrei Alexandrescu writes that Haskell supports “multi-methods” Using multi-methods, I could write (in pseudo code) collide (Asteroid, Planet) = an asteroid hit a planet collide (Asteroid, Earth) = the end of the dinos ... collide (Planet,

Re: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread Dan Weston
Remember that type classes do not provide object-oriented functionality. The dispatch is static, not dynamic. Although OOP can be simulated in Haskell, it is not a natural idiom. If you need dynamic dispatch (including multiple dispatch), you may want to reconsider your solution. Dan Weston

Re: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread Tillmann Rendel
peterv schrieb: In de book Modern C++ design, Andrei Alexandrescu writes that Haskell supports “multi-methods” http://books.google.com/books?id=aJ1av7UFBPwCpg=PA3ots=YPiJ_nWi6Ydq=moder n+C%2B%2Bsig=FWO6SVfIrgtCWifj9yYHj3bnplQ#PPA263,M1 Chapter 11, Page 263 of this books: The C++ virtual

Re: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread Brian Hulley
Dan Weston wrote: Remember that type classes do not provide object-oriented functionality. The dispatch is static, not dynamic. Although OOP can be simulated in Haskell, it is not a natural idiom. If you need dynamic dispatch (including multiple dispatch), you may want to reconsider your

[Haskell-cafe] Re: Newbie question: multi-methods in Haskell

2007-08-06 Thread Stefan Monnier
Remember that type classes do not provide object-oriented functionality. The dispatch is static, not dynamic. I beg to disagree. map (\n. n + n) calls different (+) operations depending on the (type of the) argument list. That's why dictionaries are passed around (they are called vtables

Re: [Haskell-cafe] creating graphics the functional way

2007-08-06 Thread Marc A. Ziegert
Am Montag, 6. August 2007 00:48 schrieb Frank Buss: I've created a small program to compose images with combinators: http://www.frank-buss.de/haskell/OlympicRings.hs.txt ... look very smooth. And it is very slow, it needs about 40 seconds on my computer to calculate the image. Using

[Haskell-cafe] Using haskell with emacs

2007-08-06 Thread Paulo J. Matos
Hi all, I'm starting to learn haskell by my own, being currently mostly a Common Lisp, Scheme, C++ programmer... I've got the haskell emacs mode but can't find a manual. Moreover, I've found some keybindings on the net but nothing that allows me to start an interpreter in emacs and send

Re: [Haskell-cafe] Using haskell with emacs

2007-08-06 Thread Thomas Schilling
On 6 aug 2007, at 22.11, Paulo J. Matos wrote: Hi all, I'm starting to learn haskell by my own, being currently mostly a Common Lisp, Scheme, C++ programmer... I've got the haskell emacs mode but can't find a manual. Moreover, I've found some keybindings on the net but nothing that allows me

RE: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread peterv
This is very nice, but it does not really solve the original problem. In your code, evaluating collide (Jupiter, Asteroid) will result in an endless loop. This is expected in your code, because no inheritance relation is present between e.g Jupiter and Planet. With multi-dispatch, it should

Re: [Haskell-cafe] Using haskell with emacs

2007-08-06 Thread Andrew Wagner
C-c C-b ... when pressed for the first time this will start an interpreter (ghci or hugs most of the time), when pressed with a running interpreter it'll switch to that buffer. C-c C-l ... Load the current file into the editor. There is no function-wise compilation. Don't forget C-c

Re: [Haskell-cafe] Using haskell with emacs

2007-08-06 Thread Jules Bean
Thomas Schilling wrote: On 6 aug 2007, at 22.11, Paulo J. Matos wrote: If you're used to Slime+Paredit, then there isn't something really comparable, but you get some basic interactive programming with the standard key-bindings: (But paredit does work in haskell-mode, and I find it

[Haskell-cafe] Java 1.5 parser in Haskell

2007-08-06 Thread tim.b
Does anyone know of a fairly complete Java 1.5 parser and abstract syntax in Haskell? I've looked around quite a bit to no avail. Thanks, - Tim -- View this message in context: http://www.nabble.com/Java-1.5-parser-in-Haskell-tf4227017.html#a12025365 Sent from the Haskell - Haskell-Cafe mailing

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Hugh Perkins
Note that the official way to solve sudoku is to use dancing links, but I guess you are creating a naive implementation precisely as a base-line against which to measure other implementations? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Type without a data constructor?

2007-08-06 Thread Rahul Kapoor
Most examples for defining algebraic types include data constructors like so: data Tree a = Tip | Node a (Tree a) (Tree a) I by mistake defined a type which did not specify a data constructor : data SearchCondition = Term Bool | SearchCondition :||: (Term Bool) data Term a = Constant a sc ::

Re: [Haskell-cafe] Type without a data constructor?

2007-08-06 Thread Neil Mitchell
Hi I by mistake defined a type which did not specify a data constructor So the question is what are types with no constructors good for? A simple example would be appreciated. They are called phantom types, and can be used for ensuring properties at the type level. I wrote about them in a

Re: [Haskell-cafe] Type without a data constructor?

2007-08-06 Thread Dan Weston
The answer would be phantom types, but your example doesn't use them. Each of your types has at least one constructor: Possibly you overlooked the infix constructor :||: ? Tree a has 2 constructors: Tip and Node SearchCondition has 2 constructors: Term and (:||:) Term a has

Re: [Haskell-cafe] Type without a data constructor?

2007-08-06 Thread Robert Dockins
On Monday 06 August 2007 19:23, Rahul Kapoor wrote: Most examples for defining algebraic types include data constructors like so: data Tree a = Tip | Node a (Tree a) (Tree a) I by mistake defined a type which did not specify a data constructor : In this example, you have two different uses

[Haskell-cafe] Re: Type without a data constructor?

2007-08-06 Thread Aaron Denney
On 2007-08-06, Rahul Kapoor [EMAIL PROTECTED] wrote: I by mistake defined a type which did not specify a data constructor : No, you didn't. Both types have data constructors. data SearchCondition = Term Bool | SearchCondition :||: (Term Bool) data Term a = Constant a sc :: SearchCondition

Re: [Haskell-cafe] Re: Type without a data constructor?

2007-08-06 Thread Rahul Kapoor
Constructors and names of data types live in separate namespaces. The above fact was the cause of all my confusion. It just slipped out of my mind. Cheers, Rahul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Daniel Fischer
Hi, Am Montag, 6. August 2007 15:07 schrieb Adrian Neumann: -BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Hi, I wrote a brute-force sudoku solver. It takes a [[Int]] and spits out the first solution it finds. Why is it, that [0,0,0,7,0,6,9,0,0] [9,0,0,0,0,4,7,0,0]

Re: [Haskell-cafe] Java 1.5 parser in Haskell

2007-08-06 Thread Andrew Wagner
I know this isn't quite what you asked, but java has a very clearly laid-out grammar in EBNF at http://java.sun.com/docs/books/jls/first_edition/html/19.doc.html . Between that and Parsec, I would think it would be fairly simple to write a parser. Of course, adding semantics is another story. On

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Vimal
On 8/7/07, Hugh Perkins [EMAIL PROTECTED] wrote: Note that the official way to solve sudoku is to use dancing links, but I guess you are creating a naive implementation precisely as a base-line against which to measure other implementations? Well, Dancing Links (DLX) is just a data structure +

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Donald Bruce Stewart
j.vimal: On 8/7/07, Hugh Perkins [EMAIL PROTECTED] wrote: Note that the official way to solve sudoku is to use dancing links, but I guess you are creating a naive implementation precisely as a base-line against which to measure other implementations? Well, Dancing Links (DLX) is just a

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Hugh Perkins
On 8/7/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote: See also, http://haskell.org/haskellwiki/Sudoku -- Don Just out of ... errr curiosity... which of those implementations is the fastest? ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Donald Bruce Stewart
hughperkins: On 8/7/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote: See also, [2]http://haskell.org/haskellwiki/Sudoku -- Don Just out of ... errr curiosity... which of those implementations is the fastest? No idea. You could compile them all

[Haskell-cafe] combinators for a simple grammar

2007-08-06 Thread Rahul Kapoor
I am having problems coming up with nice combinators for a simple DSEL. The abstract syntax is simply given by the types: data SearchCondition = SearchCondition BoolTerm | OpOr SearchCondition BoolTerm data BoolTerm = BoolTerm BoolFactor | OpAnd BoolTerm BoolFactor data BoolFactor = Constant

Re: [Haskell-cafe] combinators for a simple grammar

2007-08-06 Thread Stefan O'Rear
On Mon, Aug 06, 2007 at 10:33:01PM -0400, Rahul Kapoor wrote: I am having problems coming up with nice combinators for a simple DSEL. The abstract syntax is simply given by the types: data SearchCondition = SearchCondition BoolTerm | OpOr SearchCondition BoolTerm data BoolTerm =

Re: [Haskell-cafe] combinators for a simple grammar

2007-08-06 Thread Jonathan Cast
On Monday 06 August 2007, Rahul Kapoor wrote: I am having problems coming up with nice combinators for a simple DSEL. The abstract syntax is simply given by the types: snip Or is it a better idea to just remove the precedence rules from the types and move it the part of the code that

RE: [Haskell-cafe] Re: creating graphics the functional way

2007-08-06 Thread Frank Buss
apfelmus wrote: The idea of representing images simply by a function Int - Int - RGB is great :) You may want to look at Pan and its various offsprings, in particular Pancito http://www.haskell.org/haskellwiki/Applications_and_libraries/ Graphics#Pan this looks interesting.

RE: [Haskell-cafe] creating graphics the functional way

2007-08-06 Thread Frank Buss
Marc A. Ziegert wrote: in that source file, you define Size and Pixel as structs of Integers. that are neither unsigned chars (8_bit) nor ints (32-64_bit) nor floats (32_bit) but an artificial oo_bit int (1 int + list of bytes). i'm sure you will gain a speedup by redefining these

[Haskell-cafe] Monad for Set?

2007-08-06 Thread Ronald Guida
Hi, I'm pondering, is it possible to define a Set monad analogous to the List monad? My thinking is as follows: * fmap f x would apply f to each element in a set x * return x would create a singleton set {x} * join x, where x is a set of sets: x = {x1, x2, ... xn}, would form

Re: [Haskell-cafe] Sudoku Solver

2007-08-06 Thread Hugh Perkins
On 8/7/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote: No idea. You could compile them all with -O2, run them on a set of puzzles, and produce a table of results :-) Well I could, but I wont ;-) If you had to guess which one is fastest which one would you guess? I'm a little surprised no

Re: [Haskell-cafe] Monad for Set?

2007-08-06 Thread Matthew Brecknell
Ronald Guida: I'm pondering, is it possible to define a Set monad analogous to the List monad? [snip] This leads me think of a different solution: What if I could define a Set monad that's smart enough to know, for any type a, whether or not (Eq a) holds, and degenerate to a blind list if

Re: [Haskell-cafe] Newbie question: multi-methods in Haskell

2007-08-06 Thread Brian Hulley
peterv wrote: This is very nice, but it does not really solve the original problem. To get Haskell to choose the best fit it's necessary to encode the location of each element in the hierarchy, so that elements deeper in the hierarchy are more instantiated than those at the top. Then