I have a simulation with a lot of function calls type F = A -> B -> C -> D , where A .. D are concrete types.
Type A objects have an average lifespan. (This is the codegolf ratrace genome .)
The most expensive calculation arises from parameter A I can easily remember this:
f1 :: F f1 a = let expensive = trace "expensive computation!" $ expensiveComputation a in \bc -> expensive
and hold some pre-processed expensive values ββthrough a partial application:
preProz :: [B -> C -> D] preProz = [f1 [], f1 [False], f2 []]
Traces show that preProz <*> [[],[[]]] <*> [1,2] does not reflect the value in my delight.
Now I have learned that some of my F will also benefit from preprocessing B This preprocessing is independent of A , and, in fact, this memoirization has no advantage
f2 a = let expensive = trace "expensive computation!" $ expensiveComputation a in \b -> let dear = trace "expensive computation!" $ expensiveComputation b in expensive + dear
because dear recounted, even equal to B
I need something like:
(B -> e) -> A -> e -> C -> D
where e should be seen. Type e is conditional here. But this makes me recalculate all the values ββof A for each B , which is just as bad, and I can not save e s, which are private to the function.
How can I memorize two parameters myself?