Re: [Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-12 Thread Raynor Vliegendhart
On 7/9/09, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Of course, some part of algorithm has to be recursive, but this can be outsourced to a general recursion scheme, like the hylomorphism hylo :: Functor f = (a - f a) - (f b - b) - (a - b) hylo f g = g . fmap (hylo f g) . f

[Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-12 Thread Heinrich Apfelmus
Raynor Vliegendhart wrote: On 7/9/09, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Of course, some part of algorithm has to be recursive, but this can be outsourced to a general recursion scheme, like the hylomorphism hylo :: Functor f = (a - f a) - (f b - b) - (a - b) hylo f g =

[Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-11 Thread Heinrich Apfelmus
Matthias Görgens wrote: Thanks. I heard about the hylo-, ana- and catamorphisms before, but never explicitly used them. Time to get started. You did use them explicitly :) , namely in treeSort = bootstrap partitionOnMedian bootstrap f = Fix . helper . f where helper = fmap (Fix .

Re: [Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-09 Thread Matthias Görgens
Interesting. Can you make the definition of quicksort non-recursive, too? Perhaps with help of a bootstrapping combinator like the one implicit in the approach I have given earlier? treeSort = bootstrap partitionOnMedian bootstrap f = Fix . helper . f where helper = fmap (Fix . helper .

[Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-09 Thread Heinrich Apfelmus
Matthias Görgens wrote: Interesting. Can you make the definition of quicksort non-recursive, too? Perhaps with help of a bootstrapping combinator like the one implicit in the approach I have given earlier? treeSort = bootstrap partitionOnMedian bootstrap f = Fix . helper . f where

Re: [Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-09 Thread Matthias Görgens
Thanks. I heard about the hylo-, ana- and catamorphisms before, but never explicitly used them. Time to get started. And yet another question: One can get the median in deterministic linear time. For quicksort choosing the median as pivot keeps the O(n log n) average running time and brings

[Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-08 Thread Heinrich Apfelmus
Matthias Görgens wrote: So, a tree like Matthias implements it is the way to go. Basically, it reifies the recursive calls of quicksort as a lazy data struture which can be evaluated piecemeal. Yes. I wonder if it is possible to use a standard (randomized quicksort) and employ some type

[Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-07 Thread Heinrich Apfelmus
Petr Pudlak wrote: about a month ago, we were discussing sorting in Haskell with a friend. We realized a nice property of lazy merge-sort (which is AFAIK the implementation of Data.List.sort): Getting the first element of the sorted list actually requires O(n) time, not O(n * log n) as in

Re: [Haskell-cafe] Re: excercise - a completely lazy sorting algorithm

2009-07-07 Thread Matthias Görgens
So, a tree like Matthias implements it is the way to go. Basically, it reifies the recursive calls of quicksort as a lazy data struture which can be evaluated piecemeal. Yes. I wonder if it is possible to use a standard (randomized quicksort) and employ some type class magic (like