parse error on input 'let' Haskell -
I want to store each letter with a string in the list that I've read from the file. That's why I'm repeating the list of strings. To get a string at a time, "st" and i = "0" are called and I am calling this function from my main, but I am getting a parse error and I can not get it. can you understand this ??
get 'st i = do if i & lt; (Length st) then print (st !! i) j = 0 let j = i let i = get j +1 'st i else print ("hi") First, let's add indentation. Haskell depends on indentation or curly braces & amp; Semi-colon:
get 'st i = do if i & lt; (Length st) then print (st !! i) j = 0 let's get j = i let i = j + 1 get 'st i print' ("hi") Also gives an error
Temp.hs: 4: 5: Parsing error on input error ' Because you have your then For the chain actions in the block, the do block must be started
This is a common error for new people for Haskell then section is a single expression If you take a single out of a series of actions If you want to make a wish, you need a do .
Then let's add it:
get 's' if i & lt; (Length ST) then print (whistle !! I) Let's go = I get J = I get two I = J + 1 'Saint I and print (' Hi ') And now you compile.
There is a bunch of critics who can improve your code:
- You can use
length stO (n ^ 2) in the length of the string you can calculate it once , but ... - You can not calculate it at all Want to, and
st !! I - decodestruct the list using pattern matching; It also saves you from your weird
let j = 0; Let j = i; Let i = j + 1; Get ST I(which can be reduced toI = i + 1; 'I get St I') or betterget 'st (i + 1)- Unnecessary
< Li> Unnecessary brackets <lengthand"hi"geti <= code> - ifblock is the same expression, then you do not want to mess with anything.
In addition, you are using print , which is what you want. Print "hey" print "hey" \ n < / Code> (quote With the code) where putStr "hey" simply O (no quote) does not print and putStrLn "hey" print hey \ N .
Comments
Post a Comment