[Haskell-beginners] IO Problem

Jamie McCloskey crimbo1994 at gmail.com
Fri Oct 17 02:58:45 EDT 2008


Hi everyone,
I have just started learning Haskell, it is a very interesting language.
As a first project, I am building a brainfuck interpreter, but have hit
a stumbling block: IO. My program source is located at
http://hpaste.org/11219

My program handles the state of a brainfuck program by passing
State(lists of ints) objects around. When I added my getIn fuction,
however, it needed to return an IO State object. This broke the run
function, as it returned a State. No problem, I thought, and changed run
to return IO State. This broke my exec function, which calls run on each
element in a list.

As exec passes on the state returned by the run function to itself, it
needs to take an IO State. This causes problems in the loop function,
which calls exec on a subprogram. Because exec now takes IO State, loop
also needs to. However, loop is called by run, so now run needs to take
IO State. Now, all functions called by run need to take IO State.

All this creates a whole load of functions with IO, even though it
should not be necessary. What I would like to know, is how I can avoid
this, possibly by modifying exec to just take a State.

Whew! What a long-winded explanation!

Any ideas?

--Jamie

P.S. Please ignore my long-winded list iteration functions -- I'm
working on a cleaner version.



More information about the Beginners mailing list