#3631: Overload the Prelude iterate to support list input
---------------------------------+------------------------------------------
    Reporter:  shelbymoore3      |        Owner:                  
        Type:  feature request   |       Status:  closed          
    Priority:  normal            |    Milestone:                  
   Component:  Prelude           |      Version:  6.10.4          
    Severity:  normal            |   Resolution:  wontfix         
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Comment (by shelbymoore3):

 Correction:

 {{{
 iterate f x y = y ++ iterate f (x ++ (f x)) (f x)
 }}}

 {{{
 fibs = 0 : 1 : iterate (\x -> [last x + last init x]) [ 0 : 1 ] [] where
 }}}

 Alternative (IMHO the best):

 {{{
 iterate f x = x ++ iterate' f x [] where
    iterate' f x y = y ++ iterate' f (x ++ (f x)) (f x)
 }}}

 {{{
 fibs = iterate (\x -> [last x + last init x]) [ 0 : 1 ] where
 }}}

 Alternative (less general):

 {{{
 iterate :: ([a] -> a) -> [a] -> a -> [a]
 iterate f x y = y : iterate f (x ++ [(f x)]) (f x)
 }}}


 {{{
 fibs = 0 : iterate (\x -> last x + last init x) [0] 1 where
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3631#comment:16>
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