I'm not very familiar with monad-control, but it looks like the
equivalent of liftWith from monad-control would be a function that has
type "StateT S Q a -> Q (S -> (a, S))".  IIUC, you are suggesting that
the code would look something like "restoreT [| ... $( liftWith ( ...
) ) ... |]".

Unfortunately, I don't think that would work because GHC requires that
the contents of "$( ... )" have exactly the type "Q Exp" (or "Q Type",
etc.).  Using liftWith in that way makes the contents of "$( ... )"
have type "Q (S -> (a, S))".

On Fri, Dec 30, 2011 at 5:55 AM, James Cook <[email protected]> wrote:
> One possible option would be to make a library that has all the combinators 
> lifted to your more general type and use "lift" or "runQ" or something 
> similar for any quotes that need lifting, along with operations from 
> monad-control or monad-peel to lift quotes that also need access to the 
> StateT layer in the splice.  It's a bit messier and those libraries are 
> brain-bending at first (although definitely worth learning about), but it 
> would allow you to code in the style you're talking about with a relatively 
> small amount of extra syntactic clutter.
>
> -- James
>
> On Dec 29, 2011, at 9:51 PM, Michael D. Adams wrote:
>
>> What would it take to get an "-XOverloadedQuotes" flag of the same
>> sort as the "-XOverloadedStrings" flag?  I.e. "[| ... |]" would have
>> type "Quasi m => m Exp" instead of "Q Exp" and any splices in that
>> quotation expect the contents of that splice to have type "m Exp".
>> (Obviously, top level splices would still have type "Q Exp" otherwise
>> the compiler wouldn't know how to evaluate the monad.)
>>
>> I ran into this problem when writing a Template Haskell program in
>> which part of it operates in a "StateT S Q a" monad instead of the
>> usual "Q a" monad.  (The "S" type stores the state of a memoization
>> table of code fragments already generated.  Without it, the code would
>> loop infinitely when processing certain recursive structures.)
>>
>> It is fairly easy to declare an instance of "Quasi" for "StateT S Q",
>> so in order to keep the code clean, I'd like to use quotations with
>> splices in them (i.e. [| ... $( ... ) ... |] ) for expressing the
>> generated code.  However, quotations and splices are tied to the "Q"
>> monad which means that as it is now I have to manually write "LamE ...
>> VarP ... VarE ... etc." instead of using the much nicer quotation
>> syntax.
>>
>> Michael D. Adams
>> [email protected]
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to