1

So I'm new to Haskell and I have to program Rabin Karps algorithm. I feel like my answer should work, but I keep getting a "parse error on 'let'" error when I compile. Could anybody help me out.

Here is my code:

import Data.Char

hash :: String -> Int
hash [] = -1
hash (x:xs) = ((ord x))

rabinKarp :: String -> String -> Bool
rabinKarp [] _ = False
rabinKarp mainString patternString
    let
     hashPattern = hash patternString
     hashMain = hash (take (length pattern) mainString)
    if hashPattern == hashMain
    then True
    else rabinKarp (drop 1 mainString) patternString
5

you're missing a =, and also an in

rabinKarp mainString patternString =
    let
     hashPattern = hash patternString
     hashMain = hash (take (length pattern) mainString)
    in if hashPattern == hashMain
     then True
     else rabinKarp (drop 1 mainString) patternString

EDIT: in

1
  • Cheers man, I'm so tired I did an all nighter trying to figure out this assignment and that fixed it. I would up vote you but I need a rep of 15 or something, thanks so much!
    – Ayohaych
    Dec 17 '12 at 11:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.