parsonsmatt · GitHub

@ccycle

@ccycle

parsonsmatt

Comment on lines +3119 to +3127

avoidKeyword name = if name `elem` keywords then name ++ "_" else name

keywords :: [Text]
keywords =
["case","class","data","default","deriving","do","else"
,"if","import","in","infix","infixl","infixr","instance","let","module"
,"newtype","of","then","type","where","_"
,"foreign"
]

Collaborator

Lots of list lookups like this is pretty inefficient - would prefer to see a Set lookup

Suggested change

avoidKeyword name = if name `elem` keywords then name ++ "_" else name
keywords :: [Text]
keywords =
["case","class","data","default","deriving","do","else"
,"if","import","in","infix","infixl","infixr","instance","let","module"
,"newtype","of","then","type","where","_"
,"foreign"
]
avoidKeyword name = if name `Set.member` haskellKeywords then name ++ "_" else name
haskellKeywords :: Set Text
haskellKeywords = Set.fromList
["case","class","data","default","deriving","do","else"
,"if","import","in","infix","infixl","infixr","instance","let","module"
,"newtype","of","then","type","where","_"
,"foreign"
]

Floating it to the top-level ensures we aren't constructing the Set for each call to mkRecordName, though I would guess GHC is capable of performing that optimization on it's own

Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>

parsonsmatt

@parsonsmatt

@ccycle

ccycle deleted the fix-mkRecordName branch

March 13, 2023 08:33

Merged

7 tasks

Open

Read the original on github.com ↗