Skip to content

template-haskell: Make it easier to define an instance of Quasi

Motivation

It's currently quite laborious to give a definition of Quasi as it has 26 required methods.

This is somewhat ameliorated by the th-orphans package that gives instances for ReaderT, StateT, WriterT and RWST.

Proposal

Define a new typeclass:

class LiftQ m where
  liftQ :: Q a -> m a

and define default methods for all of the methods of Quasi except for qRecover in terms of that class lifting the operation from Q.

qRecover is a special case as there's non-trivial decisions to be made as to how you want to recover from an error.

I'm not sure if this is worthwhile but I felt like it was at least worth raising. Take a look here to see Quasi instances on hackage.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information