batterseapower at hotmail.com
Tue Feb 2 19:48:27 EST 2010
2010/2/2 Twan van Laarhoven <twanvl at gmail.com>:
> class Quoted a where
> parseQuote :: String -> a
> -- for performance reasons:
> parseQuote' :: Ghc.PackedString -> a
Thinking about it, you can use type classes to dispose of the
QuasiQuote record entirely. Instead, have:
class MyLang a where
myLang :: String -> Q a
instance MyLang Exp where
myLang = myLangSyntaxToGHCExprForSplice . myLangExpParser
... etc, MyLang instances for Pat and Type too ...
And then write:
Now the splice $(e) typechecks e as a Q Type / Q Exp / Q Decl as
required by the context it is in, and hence gets the correct instance
of MyLang. So our proposal needn't change the semantics of splice at
all - we can reuse the name overloading abilities of type classes.
It's a shame that TH is too widely used to be amenable to refactoring
into this sort of form.
More information about the Glasgow-haskell-users