Re: [Haskell-cafe] Red-Blue Stack

2008-09-27 Thread Thomas Davie
Thomas Davie wrote: In this interprettation, here's what I think is an O(1) implementation: ... rbPop :: Colour -> RBStack a -> RBStack a rbPop c Empty = error "Empty Stack, can't pop" rbPop c (More c' v asCs nextNonC) | c == c' = asCs | otherwise = rbPop c nextNonC ... Your pop does

Re: [Haskell-cafe] Red-Blue Stack

2008-09-27 Thread Matthew Eastman
Matthew Brecknell wrote: Matthew Eastman said: i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, Blue] Hmm, did you mean [Red,Blue] or [Red,Red,Red,Blue]? Judging by your implementation of remUseless, I'm guessing the latter. Yes, I meant the latter. Popping Blue in

Re: [Haskell-cafe] Red-Blue Stack

2008-09-27 Thread Thomas Davie
On 25 Sep 2008, at 06:11, Matthew Eastman wrote: Hey guys, This is probably more of a question about functional programming than it is about Haskell, but hopefully you can help me out. I'm new to thinking about things in a functional way so I'm not sure what the best way to do some thing

Re: [Haskell-cafe] Red-Blue Stack

2008-09-25 Thread Derek Elkins
On Thu, 2008-09-25 at 00:11 -0400, Matthew Eastman wrote: > Hey guys, > > This is probably more of a question about functional programming than > it is about Haskell, but hopefully you can help me out. I'm new to > thinking about things in a functional way so I'm not sure what the > best way

Re: [Haskell-cafe] Red-Blue Stack

2008-09-25 Thread Matthew Brecknell
Matthew Eastman said: > i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, > Blue] Hmm, did you mean [Red,Blue] or [Red,Red,Red,Blue]? Judging by your implementation of remUseless, I'm guessing the latter. Here is a more straightforward approach than apfelmus'. I store colou

Re: [Haskell-cafe] Red-Blue Stack

2008-09-24 Thread Jamie Brandon
Try writing data RBStack = RBS [RBSItem] [RBSItem] where the first list are all the same colour and the start of the second list is a different colour. The rest should follow naturally and you will get amortised O(1) push and pop (you occasionally have to juggle the lists). By the way, for this

[Haskell-cafe] Red-Blue Stack

2008-09-24 Thread Matthew Eastman
Hey guys, This is probably more of a question about functional programming than it is about Haskell, but hopefully you can help me out. I'm new to thinking about things in a functional way so I'm not sure what the best way to do some things are. I'm in a data structures course right now,