Re: [Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread Felipe Lessa
On Sun, Mar 21, 2010 at 03:39:08PM +1000, Yasir Arsanukaev wrote: > I'm interested not in particular algorithm performance but rather in > performance of its implementations in various languages. Is your C program using lists or arrays? These are different algorithms. -- Felipe.

Re: [Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-21 Thread Mark Lentczner
You might express the algorithm more directly in Haskell, without the reverse calls: bubblesort :: (Ord a) => [a] -> [a] bubblesort [] = [] bubblesort (x0:xs) = case bubble x0 xs of (xs', True) -> bubblesort xs' (xs', False) -> xs' where bubble x1 (x2:xs) | x1 <= x2 = merge x1

Re: [Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-20 Thread Casey Hawthorne
You may want to use a mutable array. >The performance may suffer from the memory allocation for the list. I >wonder if it's possible to make Haskell implementation work faster >without changing the algorithm (there's are actually a few tricks to >make it work faster, but neither implementations ha

[Haskell-cafe] Bubble sort algorithm implementations (Haskell vs. C)

2010-03-20 Thread Yasir Arsanukaev
Hello. I have written 2 implementation of bubble sort algorithm in C and Haskell. Haskell implementation: module Main where main = do contents <- readFile "./data" print "Data loaded. Sorting.." let newcontents = bubblesort contents writeFile "./data_new_ghc" newcontents print