Opened 5 years ago

Closed 5 years ago

#9540 closed bug (fixed)

words is not a good producer; unwords is not a good consumer

Reported by: dfeuer Owned by:
Priority: normal Milestone: 7.10.1
Component: Core Libraries Version: 7.9
Keywords: fusion Cc: core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D375
Wiki Page:


I think we can do something like this, once we've fixed unfoldr:

unwords = unfoldr go
    go [] = Nothing
    go ("":ws) = Just (' ', ws)
    go ((l:ls):ws) = Just (l, ls:ws)

With my draft unfoldr, GHC turns this into

lvl_r1EN = C# ' '

Rec {
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 =
  \ 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 = \ b'_a1F9 -> unwords_go b'_a1F9

To my untrained eye, that looks pretty reasonable.

Change History (3)

comment:1 Changed 5 years ago by dfeuer

Differential Rev(s): D375
Milestone: 7.10.1
Status: newpatch
Summary: unwords is not a good producerwords is not a good producer; unwords is not a good consumer

I've changed my mind; I think it probably (but not necessarily) makes more sense to make unwords be a good consumer and words a good producer, so they can play nice with each other. If I could make unwords both, that'd be the ideal, but we can at least go one way.

comment:2 Changed 5 years ago by thomie

Cc: core-libraries-committee@… added
Component: CompilerCore Libraries
Differential Rev(s): D375Phab:D375

comment:3 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.