3 kyu

Recurrence relations

Description:

Say we have a function of this type:

f :: Ord a => a -> Either b ([a], [b] -> b)

any recursive function of one argument can be implemented in such a way that it fits this type signature - provided with an argument it returns either the result (Left-case) or a pair of new arguments for the function and a function to fold the results (Right-case). For example

factorial i | i == 0    = Left 1
            | otherwise = Right ([i-1], (*i).head) 

fibonacci i | i < 2     = Left i
            | otherwise = Right ([i-1, i-2], sum)

gives us the usual factorial and Fibonacci functions (for more examples, see the test cases).

Task

Your task is to write an evaluator for such functions, i.e a function

evaluateFunction :: Ord a => (a -> Either b ([a], [b] -> b)) -> a -> b

that takes a function of a previously described form and turns it into a simple a -> b function (again, see examples in the test cases).

Performance
Fundamentals

More By Author:

Check out these other kata created by Ivana

Stats:

CreatedMar 16, 2015
PublishedMar 16, 2015
Warriors Trained959
Total Skips254
Total Code Submissions1027
Total Times Completed281
Haskell Completions281
Total Stars96
% of votes with a positive feedback rating99% of 72
Total "Very Satisfied" Votes71
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes1
Total Rank Assessments11
Average Assessed Rank
3 kyu
Highest Assessed Rank
2 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • Ivana Avatar
  • jhoffner Avatar
  • JohanWiltink Avatar
  • Voile Avatar
Ad