I played around with symbolVal
and template haskell as follows on ghci.
>>> :set -XTemplateHaskell -XQuasiQuotes -XDataKinds
>>> import Language.Haskell.TH
>>> import Data.Proxy
>>> import GHC.TypeLits
>>> $([| symbolVal (Proxy :: Proxy "foo") |]) -- Code (1)
"foo"
>>> runQ [| symbolVal (Proxy :: Proxy "foo") |]
AppE (VarE GHC.TypeLits.symbolVal) (SigE (ConE Data.Proxy.Proxy) (AppT (ConT Data.Proxy.Proxy) (LitT (StrTyLit "foo"))))
>>> $(appE (varE 'symbolVal) (sigE (conE ''Proxy) (appT (conT ''Proxy) (litT (strTyLit "foo")))))
<interactive>:9:3: error:
• Type constructor ‘Proxy’ used where a value identifier was expected
• In the first argument of ‘symbolVal’, namely
‘Proxy :: Proxy "foo"’
In the expression: (symbolVal (Proxy :: Proxy "foo"))
In an equation for ‘it’: it = (symbolVal (Proxy :: Proxy "foo"))
Why this error occurs though Code (1)
works well?
How we can use type level string in template haskell?