-
Notifications
You must be signed in to change notification settings - Fork 32
declareHasChunkRefs: Generate instances of HasChunkRefs where possible
#4476
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1300982
wip: using deriving-via to help automate instances of HasChunkRefs
balacij 7ac6091
wip: add more instances of HasChunkRefs and minor exports clean-up
balacij 07f54c9
wip: cut down scope to only generating HasChunkRefs instances
balacij f6a8fad
Merge remote-tracking branch 'origin/main' into derivingHasChunkRefs
Xinlu-Y 76ca128
Merge branch 'main' of github.com:JacquesCarette/Drasil into deriving…
balacij 9afe132
Update drasil-database README.md
balacij 340ce2f
Remove note about moving `deriveGenerically` -- Each usage of TH needs
balacij 0edda1b
`drasil-database`: Clean up `TH.hs`.
balacij 3934014
`drasil-lang`: Add default language flags to default build: DerivingVia,
balacij dd84436
`drasil-database`: Clarify that `TypedUIDRef`s are *UID references*.
balacij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| {-# LANGUAGE TemplateHaskellQuotes #-} | ||
| module Drasil.Database.TH ( | ||
| -- * The Magic | ||
| declareHasChunkRefs, | ||
| -- * Re-exports from GHC.Generics for convenience | ||
| Generic, | ||
| Generically(..) | ||
| ) where | ||
|
|
||
| import GHC.Generics (Generic, Generically(..)) | ||
| import Language.Haskell.TH (Name, Q, Dec(..), Type(..), DerivStrategy(..)) | ||
|
|
||
| import Drasil.Database.Chunk (HasChunkRefs) | ||
|
|
||
| -- | Declares that a type is a chunk type; Generates an instance of | ||
| -- 'HasChunkRefs'. | ||
| declareHasChunkRefs :: Name -> Q [Dec] | ||
| declareHasChunkRefs = deriveGenerically [''HasChunkRefs] | ||
|
|
||
| -- | Generates: | ||
| -- | ||
| -- 1. A 'Generic' instance for the type: | ||
| -- @ | ||
| -- deriving stock instance Generic Ty | ||
| -- @ | ||
| -- | ||
| -- 2. For all type classes to be derived generically: | ||
| -- @ | ||
| -- deriving via Generically Ty instance TheClass Ty | ||
| -- @ | ||
| deriveGenerically :: [Name] -> Name -> Q [Dec] | ||
| deriveGenerically clss ty = do | ||
| let typeCon = ConT ty | ||
|
|
||
| -- deriving stock instance Generic Ty | ||
| drvGeneric = StandaloneDerivD | ||
| (Just StockStrategy) | ||
| [] | ||
| (AppT (ConT ''Generic) typeCon) | ||
|
|
||
| -- deriving via Generically Ty instance TheClass Ty | ||
| drvCls cls = StandaloneDerivD | ||
| (Just (ViaStrategy (AppT (ConT ''Generically) typeCon))) | ||
| [] | ||
| (AppT (ConT cls) typeCon) | ||
|
|
||
| -- Gather all classes we want to derive generically | ||
| clsDrvs = map drvCls clss | ||
|
|
||
| return $ drvGeneric : clsDrvs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ dependencies: | |
| - aeson | ||
| - containers | ||
| - lens | ||
| - template-haskell | ||
| - text | ||
| - drasil-utils | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.