ray
ray

Reputation: 33

This error keeps occurring in haskell any idea on how to fix it?

step :: [Int] -> String -> [Int]
step :: (Num a, Read a) => String -> a
step = head . foldl foldingFunction [] . words
where   foldingFunction (x:y:ys) "*" = (x * y):ys
        foldingFunction (x:y:ys) "+" = (x + y):ys
        foldingFunction (x:y:ys) "/" = (x / y):ys
        foldingFunction (x:y:ys) "-" = (y - x):ys
        foldingFunction xs numberString = read numberString:xs

The code above keeps giving this error: I have tried to fix it by changing step to solveRPN and tried taking out the square brackets [], but i keep getting this error.

haskell.hs:4:1: error: parse error on input ‘where’
  |
4 | where   foldingFunction (x:y:ys) "*" = (x * y):ys
  | ^^^^^
Failed, no modules loaded.

Upvotes: 1

Views: 100

Answers (1)

Thomas M. DuBuisson
Thomas M. DuBuisson

Reputation: 64750

There are a number of problems here.

  1. Do not use two type signatures for a single function. You have step :: ... twice, pick one signatures and delete the other.
  2. where must be indented.
  3. Your function isn't type-correct so you'll still have things to work through.

Upvotes: 6

Related Questions