[GHC] #13823: Use NonEmpty lists in more places in the GHC API

GHC ghc-devs at haskell.org
Tue Jun 13 17:19:18 UTC 2017


#13823: Use NonEmpty lists in more places in the GHC API
-------------------------------------+-------------------------------------
           Reporter:  RyanGlScott    |             Owner:  (none)
               Type:  task           |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:  #8782
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 After GHC 8.2 is released and we drop support for building GHC with 7.10,
 we should try to use `Data.List.NonEmpty` in more places in the GHC API. I
 ran into this issue recently when using some functions from `ListSetOps`:

 {{{#!hs
 removeDups :: (a -> a -> Ordering) -> [a] -> ([a], [[a]])
 findDupsEq :: (a -> a -> Bool) -> [a] -> [[a]]
 equivClasses :: (a -> a -> Ordering) -> [a] -> [[a]]
 }}}

 These type signatures are terrible. Really, they should be:

 {{{#!hs
 removeDups :: (a -> a -> Ordering) -> [a] -> ([a], [NonEmpty a])
 findDupsEq :: (a -> a -> Bool) -> [a] -> [NonEmpty a]
 equivClasses :: (a -> a -> Ordering) -> [a] -> [NonEmpty a]
 }}}

 Since 90% of the time, the first thing you do after finding duplicates is
 to take a representative from the duplicate set. With lists, this requires
 the partial operation `head`, but with `NonEmpty`, this can be total like
 it was intended to be.

 I'm sure there are other places in the API that could benefit from
 `NonEmpty`, so if you have any suggestions, please leave them here.

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


More information about the ghc-tickets mailing list