Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Evan Laforge
BTW, I notice that your merges, like mine, are left-biased. This is a useful property (my callers require it), and doesn't seem to cost anything to implement, so maybe you could commit to it in the documentation? By left-biased I mean that when elements compare equal, pick the leftmost one, e.g.

[Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Heinrich Apfelmus
Leon Smith wrote: On Wed, Feb 17, 2010 at 6:58 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Ah, I meant to use the union' from your previous message, but I think that doesn't work because it doesn't have the crucial property that the case union (VIP x xs) ys = ... does not

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Ben Millwood
On Thu, Feb 18, 2010 at 8:07 AM, Evan Laforge qdun...@gmail.com wrote: And BTW again, here's something I've occasionally found useful: -- | Handy to merge or sort a descending list. reverse_compare :: (Ord a) = a - a - Ordering reverse_compare a b = case compare a b of    LT - GT    EQ - EQ

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Leon Smith
On Thu, Feb 18, 2010 at 2:32 AM, Evan Laforge qdun...@gmail.com wrote: By purest coincidence I just wrote the exact same function (the simple mergeAll', not the VIP one).  Well, extensionally the same... intensionally mine is 32 complicated lines and equivalent to the 3 line mergeAll'.  I even

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Leon Smith
On Thu, Feb 18, 2010 at 3:07 AM, Evan Laforge qdun...@gmail.com wrote: BTW, I notice that your merges, like mine, are left-biased.  This is a useful property (my callers require it), and doesn't seem to cost anything to implement, so maybe you could commit to it in the documentation? Also, I

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-18 Thread Evan Laforge
On Thu, Feb 18, 2010 at 5:22 PM, Leon Smith leon.p.sm...@gmail.com wrote: On Thu, Feb 18, 2010 at 3:07 AM, Evan Laforge qdun...@gmail.com wrote: BTW, I notice that your merges, like mine, are left-biased.  This is a useful property (my callers require it), and doesn't seem to cost anything to

[Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Heinrich Apfelmus
Leon Smith wrote: Heinrich Apfelmus wrote: I see no obvious deficiencies. :) Personally, I'd probably structure it like http://www.haskell.org/haskellwiki/Prime_numbers#Implicit_Heap This variant, based on the wiki article, is cleaner, slightly simpler, appears to be just as fast,

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Ozgur Akgun
The easiest solution is simply to define unionAll = nub . mergeAll where -- specialized definition of nub nub = map head . groupBy (==) Talking about the easiest solution, I guess this is a quite easy way of defining unionAll as well: http://gist.github.com/306782

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Daniel Fischer
Am Mittwoch 17 Februar 2010 17:46:38 schrieb Ozgur Akgun: The easiest solution is simply to define unionAll = nub . mergeAll where -- specialized definition of nub nub = map head . groupBy (==) Talking about the easiest solution, I guess this is a quite easy

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Ozgur Akgun
Ooops I thought the inner lists are possibly of infinite size. On 17 February 2010 17:16, Daniel Fischer daniel.is.fisc...@web.de wrote: Am Mittwoch 17 Februar 2010 17:46:38 schrieb Ozgur Akgun: The easiest solution is simply to define unionAll = nub . mergeAll where

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Daniel Fischer
Am Mittwoch 17 Februar 2010 18:59:42 schrieb Ozgur Akgun: Ooops I thought the inner lists are possibly of infinite size. Both, I think. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Leon Smith
On Wed, Feb 17, 2010 at 6:58 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Ah, I meant to use the  union'  from your previous message, but I think that doesn't work because it doesn't have the crucial property that the case    union (VIP x xs) ys = ... does not pattern match on the

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Leon Smith
On Wed, Feb 17, 2010 at 6:58 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Ah, I meant to use the union' from your previous message, but I think that doesn't work because it doesn't have the crucial property that the case union (VIP x xs) ys = ... does not pattern match on the

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-17 Thread Evan Laforge
By purest coincidence I just wrote the exact same function (the simple mergeAll', not the VIP one). Well, extensionally the same... intensionally mine is 32 complicated lines and equivalent to the 3 line mergeAll'. I even thought of short solution by thinking that pulling the first element

[Haskell-cafe] Re: Implementing unionAll

2010-02-16 Thread Heinrich Apfelmus
Leon Smith wrote: With the urging and assistance of Omar Antolín Camarena, I will be adding two functions to data-ordlist: mergeAll and unionAll, which merge (or union) a potentially infinite list of potentially infinite ordered lists, under the assumption that the heads of the non-empty

Re: [Haskell-cafe] Re: Implementing unionAll

2010-02-16 Thread Leon Smith
I see no obvious deficiencies. :) Personally, I'd probably structure it like http://www.haskell.org/haskellwiki/Prime_numbers#Implicit_Heap This variant, based on the wiki article, is cleaner, slightly simpler, appears to be just as fast, and allocates slightly less memory: import