[Haskell-cafe] Help: Main: thread blocked in MVar operation
"José A. Lopes"
jose.lopes at ist.utl.pt
Sun Nov 4 20:20:26 CET 2012
So, I couldn't really get a small code sample.
But I have a new example of the same problem.
Anyway, let me just give you the overall picture.
I am building an interpreter and I want to evaluate
the definition of a recursive function. This entails
registering the function symbol in the symbol table
while at the same time associating the function name
to the expression that represents the function body.
Naturally, the expression needs to be evaluated, thus
the circularity and the DoRec extension as in the
evalM (DefnStx str body) =
do rec addBindM str expr
expr <- evalM body
I am using the state monad so I don't have to manually
pass the symbol table around all the time. Now, there are
two things: the first is that this works with the state monad
without any problem:
type InterpreterM a = StateT ExprEnv a
The second is that, similarly to the previous email, when I use
the state monad transformer the program no longer works.
With the IO monad as the wrapped monad the program
crashed with the "MVar..." error message.
In the new code I am no longer using the IO monad. Instead, I
am using the Error monad. So I have the following definition
type InterpreterM a = StateT ExprEnv (Either String) a
With this definition, the program enters an infinite loop. I am
not even using the "throwError" and "catchError" functions
yet! I just change the definition of InterpreterM, which is the
What can I do ?
On 24-10-2012 01:01, Joey Adams wrote:
> On Tue, Oct 23, 2012 at 5:03 PM, "José A. Lopes" <jose.lopes at ist.utl.pt> wrote:
>> Hey everyone,
>> I changed my code I now I get the following error message
>> Main: thread blocked indefinitely in an MVar operation
>> Before the change, I was using the State monad with runState.
>> Then, I changed the code to use the StateT monad transformer wrapped around
>> IO monad and runStateT.
>> And this change introduced the error message.
>> BTW I am using DoRec extension, maybe it is the source of the problem, but I
>> don't know.
> See if you can reproduce the problem using a small code sample. The
> problem is likely that your program is trying to use a state value
> that hasn't been produced yet.
> DoRec uses fixIO for the IO monad. fixIO passes a callback its own
> return value. It's not magic; it only works if the thunk is not
> forced within the callback.
> Take a look at how fixIO is implemented:
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon
More information about the Haskell-Cafe