group by using groupWith seems stricter than it need be
import GHC.Exts (the, groupWith) is = [1..10] fs = map ((,) False) is ts = map ((,) True ) is r1 = [(the b, take 5 n) | (b,n) <- ts ++ fs, then group by b using groupWith] r2 = [(the b, take 5 n) | (b,n) <- ts ++ fs ++ [undefined], then group by b using groupWith] r3 = take 2 r2
As of GHC 8.2.1, both r2 and r3 fail.
While getting r2 to work seems difficult - it would require realizing that the domain of Bool has been satisfied - r3 seems like it might be more feasible to get working.
As a motivator, this pattern is pretty common in data science, where we want to map elements of a large list to a small result domain and get examples of those elements with each result without iterating through the whole list.