RosettaCodeData/Task/Longest-common-subsequence/Haskell/longest-common-subsequence-2.hs

14 lines
421 B
Haskell
Raw Permalink Normal View History

2013-10-27 22:24:23 +00:00
import qualified Data.MemoCombinators as M
2013-04-10 21:29:02 -07:00
2013-10-27 22:24:23 +00:00
lcs = memoize lcsm
where
lcsm [] _ = []
lcsm _ [] = []
lcsm (x:xs) (y:ys)
| x == y = x : lcs xs ys
| otherwise = maxl (lcs (x:xs) ys) (lcs xs (y:ys))
maxl x y = if length x > length y then x else y
memoize = M.memo2 mString mString
mString = M.list M.char -- Chars, but you can specify any type you need for the memo