Last active
July 15, 2019 05:21
-
-
Save fragamus/2ce047f46eefe5e6eadde586538e3694 to your computer and use it in GitHub Desktop.
This file contains 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
NOTE: the types used below, e.g. Name or UnQual come from Language.Haskell.Exts | |
I am using generic-lens to do this kind of traversal: | |
putStrLn $ show $ toListOf (types @(Name SrcSpanInfo)) foo | |
When foo is this expression it works fine: | |
(UnQual (SrcSpanInfo {srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, srcInfoPoints = []}) | |
(Ident (SrcSpanInfo {srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, srcInfoPoints = []}) "DeclHead")) | |
When foo is this expression it does not compile: | |
(TyCon (SrcSpanInfo {srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, srcInfoPoints = []}) | |
(UnQual (SrcSpanInfo {srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, srcInfoPoints = []}) | |
(Ident (SrcSpanInfo {srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, srcInfoPoints = []}) "DeclHead"))) | |
The error message GHC gives is: | |
• | No instance for ‘Generic (GHC.Real.Ratio Integer)’ | |
| arising from a generic traversal. | |
| Either derive the instance, or define a custom traversal using ‘HasTypesCustom’ | |
• In the first argument of ‘toListOf’, namely | |
‘(types @(Name SrcSpanInfo))’ | |
In the expression: toListOf (types @(Name SrcSpanInfo)) | |
In the second argument of ‘($)’, namely | |
‘toListOf (types @(Name SrcSpanInfo)) | |
$ (TyCon | |
(SrcSpanInfo | |
{srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, | |
srcInfoPoints = []}) | |
(UnQual | |
(SrcSpanInfo | |
{srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, | |
srcInfoPoints = []}) | |
(Ident | |
(SrcSpanInfo | |
{srcInfoSpan = SrcSpan "Syntax.hs" 268 24 268 32, | |
srcInfoPoints = []}) | |
"DeclHead")))’ | |
For your reference, the constructor used above, TyCon, is part of the algebraic data type "Type" defined in | |
https://hackage.haskell.org/package/haskell-src-exts-1.21.0/docs/Language-Haskell-Exts-Syntax.html#t:Type | |
I noticed that the constructor Splice refers to Exp, so this may be the constructor that pulls in Ratio. | |
Since I can't get rid of Ratio, I am going to need to conjure a Generic instance for it. If anyone has | |
guidance on that I would greatly appreciate it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment