Skip to content

Tactic plugin: Excludes Dictionary arguments in GADTs in Destruct Tactic #474

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

Merged
merged 6 commits into from
Oct 7, 2020
Merged

Tactic plugin: Excludes Dictionary arguments in GADTs in Destruct Tactic #474

merged 6 commits into from
Oct 7, 2020

Conversation

konn
Copy link
Collaborator

@konn konn commented Oct 7, 2020

Consider the following:

{-# LANGUAGE GADTs #-}
module GoldenGADTDestruct where
data CtxGADT where
  MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT

ctxGADT :: CtxGADT -> String
ctxGADT gadt = _decons

If we select case split on gadt at _decons, the Tactic Plugin in HEAD introduces instance dictionary in data constructor:

{-# LANGUAGE GADTs #-}
module T4 where
data CtxGADT where
  MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT

ctxGADT :: CtxGADT -> Bool
ctxGADT gadt = (case gadt of { (MkCtxGADT sa ea a) -> _ })

As it stands, generated pattern includes dictionary argumetns, which must not (cannot) appear in the source language.
This behaviour is due to the call to the dataConInstArgTys, which also includes dictionary argument.
This pull-request changes to use dataConInstOrigArgTys, which excludes dictionaries and adds a golden test for destructing GADTs, and the above case-splitting generates the expected result:

ctxGADT :: CtxGADT -> Bool
ctxGADT gadt = (case gadt of { (MkCtxGADT a) -> _ })

One concern: I also change the use of dataConInstArgTys in buildDataCon to dataConInstOrigArgTys. This should also correct the expression constructed by Homo or Auto tactic, but the generated expressions don't take type-level constraints into account. Any thoughts?

@alanz
Copy link
Collaborator

alanz commented Oct 7, 2020

cc @isovector @TOTBWF

@konn
Copy link
Collaborator Author

konn commented Oct 7, 2020

OMG it hangs with >= 8.8...

@konn
Copy link
Collaborator Author

konn commented Oct 7, 2020

I introduced the variant of dataConInstArgTys which excludes isClassTyCon after wards.
It seems still failing in 8.10.2, but it is due to dependency issue?

@jneira
Copy link
Member

jneira commented Oct 7, 2020

Yeah data-tree-print-0.1.0.2 should be added to stack-8.10.2.yaml to make it work

@konn
Copy link
Collaborator Author

konn commented Oct 7, 2020

Ok, it seems all CI passed!

@isovector
Copy link
Collaborator

Looks great! Thanks so much, @konn!

@jneira jneira merged commit b1f3c31 into haskell:master Oct 7, 2020
@konn konn deleted the tactic-exclude-dictionary branch October 7, 2020 15:43
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

Successfully merging this pull request may close these issues.

4 participants