[Haskell-cafe] Weaving fun

Yitzchak Gale gale at sefer.org
Sun Apr 15 05:07:31 EDT 2007


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 _             = []

\end{code}

Yes, it also weaves infinite lists.

Regards,
Yitz


More information about the Haskell-Cafe mailing list