Re: [Haskell-cafe] Parsing different types, same typeclass

2012-11-17 Thread José A. Lopes

Hey Stephen,

Thank you for the reply!

Can you elaborate on how I can use existentials?
I always up for learning new (Haskell) stuff :)

Cheers,
José

On 18-11-2012 00:19, Stephen Tetley wrote:

Being concrete, all you can do is:

parseAction :: String - Either A B
parseAction str
 | (A  `isPrefixOf` str = Left $ read str
 | (B  `isPrefixOf` str = Right $ read str


parseAction :: String - Int
parseAction str
 | (A  `isPrefixOf` str = run $ (read str :: A)
 | (B  `isPrefixOf` str = run $ (read str :: B)

As you can't return a polymorphic /a/ when you have typed the cases to A or B.

Being less concrete, no doubt you can use existentials, but at this
point I'd recommend you re-evaluate what you are trying to do.


--
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help: Main: thread blocked in MVar operation

2012-11-04 Thread José A. Lopes

Hey,

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
following code:

evalM (DefnStx str body) =
do rec addBindM str expr
   expr - evalM body
   return expr

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
evaluator monad.

What can I do ?

Best regards,
José

On 24-10-2012 01:01, Joey Adams wrote:

On Tue, Oct 23, 2012 at 5:03 PM, José A. Lopes jose.lo...@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:

 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/System-IO.html#fixIO


--
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help: Main: thread blocked in MVar operation

2012-10-23 Thread José A. Lopes

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.


Here are some specs:
ghc 7.4.2
mtl 2.1.1

If you need any other information please don't hesitate to ask.
Any help is greatly appreciated!

Cheers,
José

--
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe