[Haskell-cafe] All combinations in order.

wren romano wren at community.haskell.org
Tue May 17 00:40:32 UTC 2016


On Mon, May 16, 2016 at 1:48 PM, Christian Brolin <cbrolin at gmail.com> wrote:
> Hmm, I tried to post this via google groups but it was rejected. So I try to
> mail the list instead. Sorry for any duplicates.
>
> Hi list!
>
> How to transform a list of streams of elements into a stream of lists of
> elements such that all combinations of exactly one element of each input
> stream is present? I.e. something like this:
>
> type Stream a = [a]
> tr :: [Stream e] -> Stream [e]
> tr = sequence
>
> But I want the order of the output lists so the ones with early elements
> come first. The above starts with the first elements from each stream but
> does not treat the streams fairly. All the elements of the last stream are
> used before the next element of the second last stream is used, i.e.

For fair interleaving of streams, you should check out

    http://hackage.haskell.org/package/logict

(And be sure to read the paper, not just the Haddock documentation)

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list