To add on others' answers - there is one useful that will help you when coding (for example when solving project Euler problems): Hoogle. You can use either the command line interface or the web interface.
After you installed the Haskell platform be sure to cabal install hoogle
Hoogle usage example:
You have a function f x = 3 * x + 1
and you want to apply it on (5 :: Int)
, then apply it on the result and on that result and so on and get an infinite list of those values. You suspect there might already exist a function to assist you (not specifically for your f
though).
That function would be of type (a -> a) -> a -> [a]
if it takes f 5
or a -> (a -> a) -> [a]
if it takes 5 f
(we assume the function is for general types and not just Int
s)
$ hoogle "a -> (a -> a) -> [a]"
Prelude iterate :: (a -> a) -> a -> [a]
yep, the function you need already exists and it's called iterate
. you use it by iterate func 5
!
The result for the same example can be found here.