0

This needs to be marked a dup of "this". if anyone can close this by marking it a dup would be great. Thanks.

After implementing KMP in C++ (imperative style), I'm now trying to implement it in Haskell. I came across this post. I would like to understand how the "pre-processing" step of KMP is being done.

makeTable' []     failure = KMP True failure
makeTable' (x:xs) failure = KMP False test
   where  test  c = if c == x then success else failure c
          success = makeTable' xs (next (failure x))

I'm not able to understand how the table is being built. Especially with table being defined by calling it self (const table). Where are the values of the table being carried?

makeTable :: Eq a => [a] -> KMP a
makeTable xs = table
   where table = makeTable' xs (const table)

Appreciate any help with understanding this. Please give me any pointers to read up on, that will be helpful in understanding this piece of Haskell code.

Thanks.

asp5
  • 371
  • 1
  • 10

0 Answers0