<div dir="ltr">Mark Jones gave several talks at Advanced Functional Programming 2008. In one of them, he presented approaches to enumerating the elements of various datatypes. I found several interesting things in it, but one function stuck out as being perhaps useful in general.<br>
<br>infixr 5 |||<br><br>(|||) :: [a] -&gt; [a] -&gt; [a]<br>[]&nbsp;&nbsp;&nbsp;&nbsp; ||| ys = ys<br>(x:xs) ||| ys = x : ys ||| xs<br><br>It interleaves the elements of two lists. It&#39;s defined exactly as (++) with the exception that the arguments are swapped for the recursive application. This works nicely when one wants to merge infinite lists. For example, suppose you want a list of the enumerable numbers with a balance of positive and negative:<br>
<br>enums :: (Num a, Enum a) =&gt; [a]<br>enums = [0..] ||| map negate [1..]<br><br>You can&#39;t use (++) here, because the left side never completes.<br><br>Does (|||) seem useful to others? Is it already available in some other form (or in a library) of which I&#39;m not aware? If yes and no are the answers, then I wonder if it&#39;s useful enough for Data.List (modulo any expected renaming).<br>
<br>Sean<br></div>