[GHC] #9540: unwords is not a good producer

GHC ghc-devs at haskell.org
Tue Sep 2 03:13:17 UTC 2014


#9540: unwords is not a good producer
-------------------------------------+-------------------------------------
       Reporter:  dfeuer             |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler           |                 Version:  7.9
       Keywords:  fusion             |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Easy (less than 1  |         Type of failure:  Runtime
  hour)                              |  performance bug
     Blocked By:                     |               Test Case:
Related Tickets:                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 I think we can do something like this, once we've fixed `unfoldr`:

 {{{#!hs
 unwords = unfoldr go
   where
     go [] = Nothing
     go ("":ws) = Just (' ', ws)
     go ((l:ls):ws) = Just (l, ls:ws)
 }}}

 With my draft `unfoldr`, GHC turns this into

 {{{#!hs
 lvl_r1EN
 lvl_r1EN = C# ' '

 Rec {
 unwords_$sgo
 unwords_$sgo =
   \ sc_s1Gx sc1_s1Gy ->
     case sc_s1Gx of _ {
       [] -> : lvl_r1EN (unwords_go sc1_s1Gy);
       : l_a1Ew ls_a1Ex -> : l_a1Ew (unwords_$sgo ls_a1Ex sc1_s1Gy)
     }

 unwords_go
 unwords_go =
   \ b1_a1Fb ->
     case b1_a1Fb of _ {
       [] -> [];
       : ds_d1F5 ws_a1Ev ->
         case ds_d1F5 of _ {
           [] -> : lvl_r1EN (unwords_go ws_a1Ev);
           : l_a1Ew ls_a1Ex -> : l_a1Ew (unwords_$sgo ls_a1Ex ws_a1Ev)
         }
     }
 end Rec }

 unwords
 unwords = \ b'_a1F9 -> unwords_go b'_a1F9
 }}}

 To my untrained eye, that looks pretty reasonable.

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


More information about the ghc-tickets mailing list