I’ve been struggling with this for a while. I’m solving the longest common subsequence problem in Haskell as a learning exercise.
I have a function f1 that is passed two Ints i and j, and a function f2. f1 builds a two dimensional list so that the (i,j) location in the list is equal to f2 i j.
Now I’m trying to write a function called lcs that takes two Strings s1 and s2 and finds the longest common subsequence using f1 for memoization.
I’m not exactly sure how to set this up. Any ideas?
Code:
f1 :: Int -> Int -> (Int -> Int -> a) -> [[a]]
f2 :: Int -> Int -> a
lcs:: String -> String -> Int
I assume the
Intparameters off1are some sort of bounds? Remember that using lists give you the benefit of not needing to specify bounds (because of laziness), but it costs you slow access times.This function should do what you want
f1to do (memoize a given function):