Re: [Haskell-cafe] Weaving fun

2007-04-15 Thread Yitzchak Gale
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 _

Re: [Haskell-cafe] Weaving fun

2007-04-13 Thread Derek Elkins
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

Re: [Haskell-cafe] Weaving fun

2007-04-13 Thread Jan-Willem Maessen
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

Re: [Haskell-cafe] Weaving fun

2007-04-13 Thread Chris Kuklewicz
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]])

Re: [Haskell-cafe] Weaving fun

2007-04-13 Thread Bas van Dijk
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

Re: [Haskell-cafe] Weaving fun

2007-04-13 Thread Chris Kuklewicz
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

Re: [Haskell-cafe] Weaving fun

2007-04-12 Thread Matthew Brecknell
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

Re: [Haskell-cafe] Weaving fun

2007-04-11 Thread Chris Kuklewicz
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:

[Haskell-cafe] Weaving fun

2007-04-11 Thread Dominic Steinitz
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)) __

Re: [Haskell-cafe] Weaving fun

2007-04-11 Thread Jan-Willem Maessen
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,

Re: [Haskell-cafe] Weaving fun

2007-04-11 Thread Chris Kuklewicz
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]]

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Mark T.B. Carroll
"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

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Matthew Brecknell
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

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Dave Feustel
[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/

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Chris Mears
"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

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Ricardo Herrmann
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,

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Dave Feustel
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:

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Dan Piponi
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

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Matthew Brecknell
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

Re: [Haskell-cafe] Weaving fun

2007-04-10 Thread Brandon Michael Moore
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] >

[Haskell-cafe] Weaving fun

2007-04-10 Thread Bas van Dijk
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 :: [