
On Apr 15, 2016, at 11:51 AM, Simon Peyton Jones
Hang on! The design for typed splices, describe here, https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/BlogPostChanges says "Unlike TH, the only way to construct a value of type TExp is with a quote. You cannot drop into do-notation, nor use explicit construction of the values in the Exp algebraic data type. That restriction limits expressiveness, but it enables the strong typing guarantees."
So why does the above work? $$(e) requires a TExp, and do-notation doesn’t produce a TExp.
Indeed this is true -- this is what that page says. But it's not what's implemented: when I say $$( _ ) :: Bool, GHC tells me that the hole has type Q (TExp Bool). There still is no way to create a TExp other than to use a type TH quote. Addressing your other message: a typed quasiquoter would be somewhat limited, but not utterly silly. For example, this works:
bool :: String -> Q (TExp Bool) bool "true" = [|| True ||] bool "false" = [|| False ||] bool _ = fail "not a bool"
-- and then, in another module because of the stage restriction: yes :: Bool yes = $$(bool "true")
Now `bool` could be a typed quasiquoter. I don't know whether any of this is worth implementing, but it's not, a priori, a terrible idea. Richard
| * Should we consider it a bug (and file a ticket) that reification in | typed splices is able to observe the order of type checking, just like | reify used to do in untyped splices?
Yes I think so!!!
Simon