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
f1andf2do. Is it possible to post the code? Here are the type signatures as I understand them:f1 :: Int -> Int -> a;f2 :: Int -> Int -> a. What's the difference? - Andres Riofriof1 :: (Int -> Int -> a) -> [[a]]s.t.f1 f2 !! i !! j == f2 i j. - rampionf1 :: Int -> Int -> (Int -> Int -> a) -> [[a]]andf2 :: Int -> Int -> a? So thatf1 _ _ f2 !! i !! j == f2 i j. - Andres Riofrio