Skip to content

Commit 531ead2

Browse files
authored
Split annotationLabel and extensionLabel (#20)
* Split `annotationLabel` and `extensionLabel` * Add example
1 parent b452169 commit 531ead2

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

examples/reused-name/ReusedName.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ReusedNameBase
2+
3+
extendA "A" [] [t|Int|] $
4+
defaultExtA {
5+
typeAX = [("B", [("y", [t|String|])])]
6+
}
7+
8+
main :: IO ()
9+
main = pure ()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ReusedNameBase where
2+
import Extensible
3+
4+
extensible [d| data A = A {x :: Int} |]

extensible-data.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ executable generic
106106
hs-source-dirs: examples/generic
107107
main-is: Generic.hs
108108

109+
executable reused-name
110+
import: deps, example
111+
hs-source-dirs: examples/reused-name
112+
main-is: ReusedName.hs
113+
other-modules: ReusedNameBase
114+
109115
executable lam
110116
import: deps, example
111117
hs-source-dirs: examples/lam

src/Extensible.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,14 @@ data Config = Config {
352352
bundleName :: NameAffix,
353353
-- | Appled to constructor names to get the annotation type family's name
354354
annotationName :: NameAffix,
355+
-- | If extending a record constructor, apply this to the constructor name
356+
-- to get the annotation field's label.
357+
annotationLabel :: NameAffix,
355358
-- | Applied to datatype name to get extension constructor & type family's
356359
-- name
357360
extensionName :: NameAffix,
358-
-- | If extending a record constructor, apply this to the constructor name
359-
-- to get the extension field's label.
361+
-- | If the extending constructor is a record, apply this to the constructor
362+
-- name to get the extension field's label.
360363
extensionLabel :: NameAffix,
361364
-- | Applied to datatype name to get extension record name
362365
extRecordName :: NameAffix,
@@ -384,6 +387,7 @@ data Config = Config {
384387
-- constructorName = NameSuffix \"'\",
385388
-- bundleName = NameSuffix \"All\",
386389
-- annotationName = NamePrefix \"X\",
390+
-- annotationLabel = NamePrefix \"ann\",
387391
-- extensionName = NameSuffix \"X\",
388392
-- extensionLabel = NamePrefix \"ext\",
389393
-- extRecordName = NamePrefix \"Ext\",
@@ -400,6 +404,7 @@ defaultConfig = Config {
400404
constructorName = NameSuffix "'",
401405
bundleName = NameSuffix "All",
402406
annotationName = NamePrefix "X",
407+
annotationLabel = NamePrefix "ann",
403408
extensionName = NameSuffix "X",
404409
extensionLabel = NamePrefix "ext",
405410
extRecordName = NamePrefix "Ext",
@@ -570,7 +575,7 @@ extendCon conf nameMap ext tvs (SimpleCon name fields) = do
570575
case fields' of
571576
NormalFields fs -> pure $ NormalC name' $ fs ++ [(strict, extField)]
572577
RecFields fs ->
573-
let extLabel = applyAffix (extensionLabel conf) name in
578+
let extLabel = applyAffix (annotationLabel conf) name in
574579
pure $ RecC name' $ fs ++ [(extLabel, strict, extField)]
575580

576581
-- | Replaces recursive occurences of the datatype with the new one.

0 commit comments

Comments
 (0)