assuming that the definition is:
bf :: [Int] -> Char -> [Int] (its good practice to always specify the type)
1. you are trying to prefix an array to a number which gives a type error (line 7, xs : 0 <=> [Int] : Int)
2. you are adding an array and a number. Either you should use map (+1) array or do something to fix the semantics. again, you have two type errors (line 9, [xs + 1], line 10, [xs - 1]
also, haskell is lazy evaluating. you can simply define the stack as an infinite sequence of 0s and it will automagically extend it when needed.
you might want to use a different approach for the stack, like
Code: Select all
array :: ([Int], Int, [Int])
array = ([], 0, repeat 0)
bf :: ([Int], Int, [Int]) -> Char -> ([Int], Int, [Int])
bf (l, i, x:xs) '>' = (i:l, x, xs)
bf (x:xs,i, r ) '<' = (xs, x, i:r)
bf (l, x, r ) '+' = (l, x+1, r)
bf (l, x, r ) '-' = (l, x-1, r)
(I haven't done this for a long time, I probably missed some things)