Reputation: 31
I am having some trouble implementing a function that is supposed to call itself multiple times. Each time it updates it's values and improves it's accuracy. In the process it calls on other functions, but I know it works up 'till:
Type = [Double]
*All lists; including type: Same, but not predetermined length.
f0 :: Double -> [[Double]] -> [Double] -> Type -> Type
Typical example of function call:
f0 1.0 [[1.0, 0.5, 1.0], [1.0, -1.0, 1.0]] [1.0, 0.0] (initTypeLength 2)
What I want to do:
f1 :: Int -> Double -> [[Double]] -> [Double] -> Type -> Type
... where "Int" (i) calls for number of iterations, using f0 recursively, keeping all parameters the same except the type, which is updated.
Unsure if f0 is relevant, but in case:
f0 a (x:xs) (y:ys) type = f_other a xs ys
$ f_yet_another a x y type
What confuses me is where and how the arguments are to be stated.
So to sum up: Everything here is static, except the one list; "Type", which is updated every iteration. How do I call this? Im getting the feeling that it's obvious, but I just can't seem to figure it out in a way that haskell understands.
Upvotes: 1
Views: 509
Reputation: 2167
I think what you want is this:
f1 k a b c t = (iterate (f0 a b c) t) !! k
However, type is a keyword in Haskell, so be careful with using it as a variable name.
Also, in case you are curious as to how iterate
works, here is an implementation:
iterate :: (a -> a) -> a -> [a]
iterate f x = x : iterate f (f x)
Upvotes: 2