[Haskell-cafe] TH: quoting name and value

Sylvain Henry sylvain at haskus.fr
Mon Feb 1 09:51:00 UTC 2021


Hi,

I have the following kind of template haskell code:

module Foo where
foo :: String -> Name -> Q [Dec]
foo str name = return []

module Bar where
bar :: String
bar = "whatever"

module FooBar where
import Foo
import Bar
foo bar 'bar

It works great as in `foo` I can use both bar's Name and bar's value 
computed at compile time.

But it's unsafe for my purpose because a user could call: `foo 
"fakeBarValue"  'bar`

So the question is: is there a way to write `foo` so that it can only be 
used safely?


If not, I guess it could be possible to add a new kind of quote to TH, 
something like:

data Named a = Named Name a -- constructor not exported so that Named 
values can't be forged by users.

[namedValue||bar||] :: Named String -- new quote

What do you think?

Thanks,
Sylvain

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210201/120e1187/attachment.html>


More information about the Haskell-Cafe mailing list