Types of Typed Spliced are not inferred (looks like only checked)
I think this might be duplicate of #10271, but I'm not sure. This example is simpler.
Consider a small utility type-class (a variant discussed in !3290 (closed)
{-# LANGUAGE GADTs #-}
module CodeFromString where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
class CodeFromString a where
codeFromString :: String -> TExpQ a
instance a ~ Char => CodeFromString [a] where
codeFromString = liftTyped
It seems to work
{-# LANGUAGE TemplateHaskell #-}
module Main (main) where
import CodeFromString
main :: IO ()
main = do
putStrLn $$(codeFromString "example string")
Yet, if we make the setting just slightly more complicated like:
-- doesn't work
print $ $$(codeFromString "example string") == "example string"
-- doesn't work
print $ $$(codeFromString "example string") == ("example string" :: String)
The type of splice TExpQ String
should be easily inferrable, but GHC refuses to infer it. If we make GHC check the type with
-- works.
print $ ($$(codeFromString "example string") :: String) == ("example string" :: String)
it works again. But the explicit type-annotation / checked positions make this kind of usage quite impractical.
cc @mpickering