I am writing a Brainf*ck Interpreter in Haskell.
I am trying to print (chr (fromEnum $ getMem state)) which is just a conversion of a Word8 to Char.
Then I want to return a new state after the printing in a particular case which is
'.' -> do hPutChar stdout (chr (fromEnum $ getMem state))
hFlush stdout
return state { prog_pointer = prog_pointer state}
I get this error message
The function `hPutChar' is applied to six arguments,
but its type `Handle -> Char -> IO ()' has only two
In a stmt of a 'do' block:
hPutChar
stdout
(chr (fromEnum $ getMem state))
hFlush
stdout
return
(state {prog_pointer = prog_pointer state})
with this code
iterateBF :: BFState -> IO BFState
iterateBF state = case (program state !! prog_pointer state) of
--some more cases here--
'.' -> do hPutChar stdout (chr (fromEnum $ getMem state))
hFlush stdout
return state { prog_pointer = prog_pointer state}
I cant seem to figure out why I am getting this error.
After leftaroundabout and sabauma’s comments, i edited my code to be
iterateBF :: BFState -> IO BFState
iterateBF state = case (program state !! prog_pointer state) of
--some more cases here--
'.' -> do hPutChar stdout (chr (fromEnum $ getMem state))
hFlush stdout
return state { prog_pointer = prog_pointer state}
using only spaces this time.
However, I get parse error on input 'hFlush'
Anyone know why?
Building on leftaroundabout’s comment, you want
Note how all lines after the
doare aligned with each other, not with thedo.