<div>Hello All,<br></div><div><br></div><div>Sorry about my previous post, email was hosed. I was working on a homework problem where the task is to write the iterate function in terms of scanl. Came up with this:<br></div><div><br></div><div>myIterate f x = scanl (const.f) x (repeat x)<br></div><div><br></div><div>I went looking around for other solutions to check my work and found the following solution on the Haskell Wiki:<br></div><div><br></div><div>iterate f x = scanl f x (repeat x)<br></div><div><br></div><div>myIterate seems to work checked against the Prelude iterate but I don't know if it's a good solution or not, because the iterate solution on the Haskell Wiki throws a type error. Types of Prelude iterate and scanl are different, so I can see why, or am I missing something? Here is some REPL output:<br></div><div><br></div><div>Prelude iterate:<br></div><div>λ> take 10 (iterate (+1) 1)<br></div><div>[1,2,3,4,5,6,7,8,9,10]<br></div><div><br></div><div>myIterate:<br></div><div>λ> take 10 (myIterate (+1) 1)<br></div><div>[1,2,3,4,5,6,7,8,9,10]<br></div><div><br></div><div>Haskell Wiki solution:<br></div><div>λ> take 10 (iterate' (+1) 1)<br></div><div>error:<br></div><div>    • Occurs check: cannot construct the infinite type: a ~ a -> a<br></div><div>      Expected type: a -> a -> a<br></div><div>        Actual type: (a -> a) -> a -> a<br></div><div>    • In the first argument of ‘iterate'’, namely ‘(+ 1)’<br></div><div>      In the second argument of ‘take’, namely ‘(iterate' (+ 1) 1)’<br></div><div>      In the expression: take 10 (iterate' (+ 1) 1)<br></div><div>    • Relevant bindings include it :: [a] (bound at <interactive>:63:1)<br></div><div><br></div><div>It will work if you pass it a function that takes two parameters though:<br></div><div><br></div><div>λ> take 10 (iterate' (+) 1)<br></div><div>[1,2,3,4,5,6,7,8,9,10]<br></div><div><br></div><div>Any thoughts would be much appreciated! <br></div><div><br></div><div>Andrea<br></div><div><br></div><div><br></div>