[GHC] #14374: group by using groupWith seems stricter than it need be

GHC ghc-devs at haskell.org
Thu Oct 19 20:52:49 UTC 2017


#14374: group by using groupWith seems stricter than it need be
-------------------------------------+-------------------------------------
        Reporter:  newthin           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by newthin:

Old description:

> Using TransformListComps:
>
> {{{#!hs
> import GHC.Exts (the, groupWith)
>
> is = [1..10]
> fs = map ((,) False) is
> ts = map ((,) True ) is
>
> a = [(the b, take 5 n) | (b,n) <- ts ++ fs, then group by b using
> groupWith]
> b = [(the b, take 5 n) | (b,n) <- ts ++ fs ++ [undefined], then group by
> b using groupWith]
> c = take 2 b
> }}}
>
> As of GHC 8.2.1, both b and c fail.
>
> While getting b to work seems difficult - it would require realizing that
> the domain of Bool has been satisfied - c 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.

New description:

 Using TransformListComps:

 {{{#!hs
 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.

--

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14374#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list