Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instance Lift (Dict cls) #97

Open
Icelandjack opened this issue Dec 13, 2019 · 2 comments
Open

instance Lift (Dict cls) #97

Icelandjack opened this issue Dec 13, 2019 · 2 comments

Comments

@Icelandjack
Copy link
Contributor

Hope it's going well, do we want lift instances for Dict here?

instance Lift (Dict cls) where
 lift :: Dict cls -> Q Exp
 lift Dict = [| Dict |]

 liftTyped :: Dict cls -> Q (TExp (Dict cls))
 liftTyped Dict = [|| Dict ||]

Can it be given for a :- b?

instance Lift (a :- b) where
 lift (a :- b) -> Q Exp
 lift ..

 liftTyped :: (a :- b) -> Q (TExp (a :- b))
 liftTyped (Sub dict) = [|| Sub _ ||]
@RyanGlScott
Copy link
Collaborator

Sounds reasonable to me. Care to make a pull request?

Can it be given for a :- b?

Sure, you could do this:

instance Lift (a :- b) where
  lift :: a :- b -> Q Exp
  lift d = [| Sub (Dict \\ d) |]

  liftTyped :: a :- b -> Q (TExp (a :- b))
  liftTyped d = [|| Sub (Dict \\ d) ||]

@RyanGlScott
Copy link
Collaborator

On the other hand, @mpickering reminds me that if these instances were to be defined, they would have to be used with care, as today's typed Template Haskell is unsound. For instance, here is an example of unsoundness that can result from splicing in Dict:

f :: a => Q (TExp (Dict a))
f = liftTyped Dict
g :: a => Dict a
g = $$f
error:
    • Could not deduce: a arising from a use of ‘f’
    • In the expression: f
      In the Template Haskell splice $$f
      In the expression: $$f
    • Relevant bindings include g :: Dict a
   |
   | g = $$f
   |       ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants