On Feb 1, 2021, at 4:51 AM, Sylvain Henry <sylvain@haskus.fr> wrote:_______________________________________________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 'barIt 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 quoteWhat do you think?
Thanks,
Sylvain
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.