id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,testcase,blockedby,blocking,related,differential,wikipage
3631,Overload the Prelude iterate to support list input,shelbymoore3,,"Had to overload the Prelude function iterate to support list input. The overload could be global (should be added to Prelude), no need to wrap in where. My example fibonacci sequence usage follows.
{{{
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
}}}
Make forward iteration explicit, and remove self referential space ""leak"" above due direct recursion on fibs.
{{{
fibs = iterate (\x -> last x + last init x) [ 0 : 1 ] where
iterate :: ([a] -> [a]) -> [a] -> [a]
iterate f x = iterate f (x : (f x))
-- iterate f x == [x, f x, f (f x), ...]
}}}
Or verbosely:
{{{
fibs = iterate (\x -> fib -1 + fib -2 where fib i = | i==-1=last x | i==-2=last init x) [ 0 : 1 ]
-- negative indices in local function fib offset from end of list
}}}
P.S. Note I not using HUGS nor GHC, this is just in my head. The above are my unique solutions, didn't lift them from www. I am just learning FP and Haskell for first time in my head past few days. So this might be rubbish.",feature request,closed,normal,,Prelude,6.10.4,wontfix,,,Unknown/Multiple,Unknown/Multiple,None/Unknown,,,,,,