2 Replies - 1563 Views - Last Post: 17 December 2012 - 04:47 AM

#1 Party Boy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 23-October 12

Haskell parse error on let help please

Posted 17 December 2012 - 04:35 AM

Hey there.
I have to implement rabin karps algorithm into Haskell, I think my code is right but it's not working for me
When I compile I get an "parse error on let" error.
Just wondering if anybody could look at the code and tell me what's wrong with it, I think it could be indentation but usually Haskell tells you.
Thanks for any help!

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


Is This A Good Question/Topic? 0
  • +

Replies To: Haskell parse error on let help please

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,204
  • Joined: 21-June 11

Re: Haskell parse error on let help please

Posted 17 December 2012 - 04:41 AM

As you presumably know (you did it right everywhere else), a case of a function definition looks like functionName parameters = expression. In your last case of the rabinKarp function (on line 9), there is no =.

PS: Please don't post the same question on multiple sites on the Internet.

This post has been edited by sepp2k: 17 December 2012 - 04:45 AM

Was This Post Helpful? 1
  • +
  • -

#3 Party Boy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 23-October 12

Re: Haskell parse error on let help please

Posted 17 December 2012 - 04:47 AM

Awh shit man your dead right, I pulled an all nighter trying to get this assignment done so I was pretty tired at the end of it and missed it. I ended up getting it working so thanks for the help.
Now I have to move onto Boyer Moore haha.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1