
#14364: Reduce repetition in derived Read instances -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: task | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10980 #7258 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by tdammers): Replying to [ticket:14364 bgamari]:
Let's factor this pattern out into a `readField` helper in `GHC.Read`, {{{#!hs readField :: String -> ReadPrec a -> ReadPrec a readField fieldName readVal = do expectP (Ident fieldName) expectP (Punc "=") readVal {-# NOINLINE readField #-} }}} This will at least knock off a constant factor from the size of what should not be performance-critical code.
The `readField` function actually has to be a bit more complex than that to cater for symbol-named fields (e.g. `(#)`). We can however make the decision at compile time, because we already know the label. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14364#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler