#5083: Proposal: making inits and tails less strict
---------------------------------+------------------------------------------
    Reporter:  basvandijk        |       Owner:                
        Type:  task              |      Status:  new           
    Priority:  normal            |   Component:  libraries/base
     Version:  7.0.3             |    Keywords:                
    Testcase:                    |   Blockedby:                
          Os:  Unknown/Multiple  |    Blocking:                
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown  
---------------------------------+------------------------------------------
 I would like to propose making `inits` and `tails` less strict:

 {{{
  inits                   :: [a] -> [[a]]
 -inits []                =  [[]]
 -inits (x:xs)            =  [[]] ++ map (x:) (inits xs)

 +inits xs                =  [] : case xs of
 +                                  []   -> []
 +                                  x:xs -> map (x:) (inits xs)
 }}}

 {{{
  tails                   :: [a] -> [[a]]
 -tails []                =  [[]]
 -tails xxs@(_:xs)        =  xxs : tails xs

 +tails xxs               =  xxs : case xxs of
 +                                   []   -> []
 +                                   _:xs -> tails xs
 }}}
 Having a lazier `inits` allows the elegant:
 {{{nats = map length (inits nats)}}}
 which loops for the current definition. This definition was [http://www
 .mail-archive.com/[email protected]/msg21044.html due to John Tromp]

 In the [http://thread.gmane.org/gmane.comp.lang.haskell.libraries/15459/
 thread on the libraries list] there were some +1's and no objections.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to