Back to the original problem for a moment.
\begin{code}
import qualified Data.Sequence as Seq
import Data.Sequence ((|>), ViewL((:<)))
weave :: [[a]] -> [a]
weave = weaveSeqL . Seq.viewl . Seq.fromList
where
weaveSeqL ((x:xs) :< s) = x : weaveSeqL (Seq.viewl $ s |> xs)
weaveSeqL _
Jan-Willem Maessen wrote:
On Apr 12, 2007, at 9:39 PM, Matthew Brecknell wrote:
Jan-Willem Maessen:
Interestingly, in this particular case what we obtain is isomorphic
to constructing and reversing a list.
Jan-Willem's observation also hints at some interesting performance
characteristics o
On Apr 12, 2007, at 9:39 PM, Matthew Brecknell wrote:
Jan-Willem Maessen:
Interestingly, in this particular case what we obtain is isomorphic
to constructing and reversing a list.
Jan-Willem's observation also hints at some interesting performance
characteristics of difference lists. It's we
The fun never ends...
Bas van Dijk wrote:
> On 4/11/07, Chris Kuklewicz <[EMAIL PROTECTED]> wrote:
>> ...
>> My previous weave, uses composition of (xs:) thunks instead of pairs:
>>
>> > weave :: [[a]] -> [a]
>> > weave [] = []
>> > weave xss = helper id xss
>> > where helper :: ([[a]] -> [[a]])
On 4/11/07, Chris Kuklewicz <[EMAIL PROTECTED]> wrote:
...
My previous weave, uses composition of (xs:) thunks instead of pairs:
> weave :: [[a]] -> [a]
> weave [] = []
> weave xss = helper id xss
> where helper :: ([[a]] -> [[a]]) -> [[a]] -> [a]
> helper _rest ([]:_xss) = [] -- done
Matthew Brecknell wrote:
> Jan-Willem Maessen:
>> Interestingly, in this particular case what we obtain is isomorphic
>> to constructing and reversing a list.
>
> Jan-Willem's observation also hints at some interesting performance
> characteristics of difference lists. It's well known that diffe
Jan-Willem Maessen:
> Interestingly, in this particular case what we obtain is isomorphic
> to constructing and reversing a list.
Jan-Willem's observation also hints at some interesting performance
characteristics of difference lists. It's well known that difference
lists give O(1) concatenation
You are correct, my weave did hide the list in the explicit composition of
closure(s).
I can be even more declarative and let the closure construction be implicit in
weave' below...
(and this message should be literate Haskell)
weave' uses a fixed point and pairs to tie the knot declaratively:
I've been dying to do this all day but work and then family intervened.
Dominic.
import Data.List
weave =
unfoldr f
where
f ([],_,_) = Nothing
f (x:xs,[],zs) = Just (x,([],[],[]))
f (x:xs,ys,zs) = Just (x,(ys,zs,xs))
__
On Apr 11, 2007, at 6:00 AM, Chris Kuklewicz wrote:
I have a simply recursive solution that operates efficiently...
Bas van Dijk wrote:
Hello,
For my own exercise I'm writing a function 'weave' that "weaves" a
list of lists together. For example:
weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,
I have a simply recursive solution that operates efficiently...
Bas van Dijk wrote:
> Hello,
>
> For my own exercise I'm writing a function 'weave' that "weaves" a
> list of lists together. For example:
>
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
> weave [[1,1,1], [2,2], [3,3,3]]
"Bas van Dijk" <[EMAIL PROTECTED]> writes:
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
> weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
>
> Note that 'weave' stops when a list is empty.
My naive implementation is,
weave [] = []
weave ([]:_) = []
weave (x:xs) = head x : weave
Dave Feustel:
> Talk about synchronicity! I was just wondering whether 'weaving' of
> infinite lists is possible.
>
> eg weave the infinite lists [2,4..], [3,6..], [5,10..]
> to get [2,3,4,5,6,8,9,10,..]
>
> Is this kind of lazy evaluation possible?
The base library version of (concat . transp
[EMAIL PROTECTED]>
>Sent: Apr 10, 2007 7:24 PM
>To: Haskell-Cafe@haskell.org
>Subject: Re: [Haskell-cafe] Weaving fun
>
>This reminded me of "interleaving" as in:
>
>Backtracking, Interleaving, and Terminating Monad Transformers
>http://www.cs.rutgers.edu/~ccshan/
"Bas van Dijk" <[EMAIL PROTECTED]> writes:
> Hello,
>
> For my own exercise I'm writing a function 'weave' that "weaves" a
> list of lists together. For example:
>
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
> weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
[...]
> So I'm wonde
6:13 PM
>To: haskell-cafe@haskell.org
>Subject: [Haskell-cafe] Weaving fun
>
>Hello,
>
>For my own exercise I'm writing a function 'weave' that "weaves" a
>list of lists together. For example:
>
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,
Bas van Dijk <[EMAIL PROTECTED]>
>Sent: Apr 10, 2007 6:13 PM
>To: haskell-cafe@haskell.org
>Subject: [Haskell-cafe] Weaving fun
>
>Hello,
>
>For my own exercise I'm writing a function 'weave' that "weaves" a
>list of lists together. For example:
Here's a very different approach. I make no claim to increased
elegance or efficiency, though I find it fairly readable and its made
of reusable parts. (Of course that's how you always finds your own
code!)
import Prelude hiding (head,tail)
-- Some would say this is how head and tail should have
Bas van Dijk:
> For my own exercise I'm writing a function 'weave' that "weaves" a
> list of lists together. For example:
>
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
> weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
>
> Note that 'weave' stops when a list is empty.
This *al
On Wed, Apr 11, 2007 at 12:13:10AM +0200, Bas van Dijk wrote:
> Hello,
>
> For my own exercise I'm writing a function 'weave' that "weaves" a
> list of lists together. For example:
>
> weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
> weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
>
Hello,
For my own exercise I'm writing a function 'weave' that "weaves" a
list of lists together. For example:
weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2]
weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
Note that 'weave' stops when a list is empty. Right now I have:
weave :: [
21 matches
Mail list logo