
On Sunday 04 February 2007 14:24, Nicolas Frisby wrote:
I've always thought that when certain operations are of particular interest, it's time to use more appropriate data structures, right? Lists are great and simple and intuitive, but if you need such operations as shifts, something like a deque is the way to go.
I'm not a data structure pro, but I'm sure someone on this list could post a neat example. Or you could look for work by Osaki - he seems to be the reference for functional data structures. "Finger trees" and "tries" also get a lot of attention around here.
Also, take a look at Edison. It has a variety of sequence implementations with different properties. Several of them have efficient access to both ends of the sequence. http://www.eecs.tufts.edu/~rdocki01/edison.html
Enjoy.
On 2/4/07, Lennart Augustsson
wrote: Not much better. You could define shiftl such that is does a single traversal and returns both the last element and all but the last. That will save you one traversal.
On Feb 4, 2007, at 18:44 , Eric Olander wrote:
Hi, I'm still somewhat new to Haskell, so I'm wondering if there are better ways I could implement the following functions, especially
shiftl:
moves the first element to the end of the list
shiftr :: [a] -> [a] shiftr [] = [] shiftr (x:y) = y ++ [x]
moves the last element to the head of the list
shiftl :: [a] -> [a] shiftl [] = [] shiftl x = [last x] ++ init x
-Eric _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe