Hi Tomasz, Tomasz Zielonka wrote:
On Mon, Jan 02, 2006 at 05:16:36PM +0100, Ch. A. Herrmann wrote:
The value I want to pass for x is of type Exp. Of course, I could turn this type into (Q Exp) by applying return, but this artificial instance of the Q monad would come from nowhere, not being connected with the regular instance used, e.g., for the fresh name generation.
It seems that you are a bit confused with monads. The only monad you have here is the Q type constructor.
maybe you misunderstood me. Take the example of the ST monad. If you are in an ST monadic computation with state, then apply a non-monadic function in which you run a ST monad again, you are faced with two different states. As long as you finished the second monadic computation before you continue the first, this will not be a problem. But if you are forced to insert a monadic value (not a return value) from the second activation into the first activation, you have two different states, and you have to consider how to proceed. If you copy parts of the second activation into the first state, you'll have problem when you leave the second and continue the first activation. Thus, the only serious solution I can figure out at the moment is to ignore the state of the second activation when inserting a value from the second one in the first one. Coming back to the Q monad this would mean: ignore the name generation history from the point where the expression to be spliced was *created* and take the name generation history from the point where the splice is to be *inserted*, which is an older one. Anyway, the names inside the generated splice take the newer information from the lexical scope of the creation. However, I'm worried about that by turning an expression into a monadic form just by using *return* tags this splice with a blank name history and I hope that the quasi quote implementation will never proceed with this history but with the one from the lexical sope of the insertion point.
In all other cases that typechecker should reject badly behaving programs.
Unfortunately, I've had too many bad experiences which make me feel not that optimistic, especially when working with state. Best wishes -- Christoph