This gist demonstrates a trick I came up with which is defining
IsString
for Q (TExp a)
, where a
is lift
-able. This allows you
to write $$("...")
and have the string parsed at compile-time.
On GHC 9, you are able to write $$"..."
instead.
This offers a light-weight way to enforce compile-time constraints. It's
basically OverloadedStrings
with static checks. The inferred return type
dictates which compile-time parser will be used.
This trick works already in existing (old) GHCs.
@amesgen Does this also apply to numeric literals? $$1 etc? I seem to remember someone (perhaps you?) was patching GHC to liberalize all the places that splices can be applied.