[GHC] #9398: Data.List.cycle is not a good producer

GHC ghc-devs at haskell.org
Sun Aug 3 19:41:32 UTC 2014


#9398: Data.List.cycle is not a good producer
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:  7.8.4
             Component:              |          Version:  7.8.3
  libraries/base                     |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Easy (less than 1
  Unknown/Multiple                   |  hour)
       Type of failure:  Runtime     |       Blocked By:
  performance bug                    |  Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 Replying to [comment:5 nomeata]:
 > But note that you are pattern matching on `xs`!

 Ah, I see what you mean. That pattern match, however, is not essential.
 Suppose we leave it out. Then we get

 {{{#!hs
 cycle [] = let cyc = augment cycle' cyc in cyc
   where
     cycle' c n = foldr c n []
 }}}

 `foldr/nil` gives

 {{{#!hs
 cycle [] = let cyc = augment (\c n -> []) cyc in cyc
 }}}

 Then applying `augment`:

 {{{#!hs
 cycle [] = let cyc = [] in cyc
 }}}

 So we've turned `_|_` into `[]`, whereas a similar omission from the
 current definition of `cycle` would turn an error into a much-less-
 desirable non-termination. This is not a disaster, and in fact it makes
 sense from a monoid perspective.

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


More information about the ghc-tickets mailing list