The difficulty here is that lexId in the library Text.Read.Lex doesn't recognise A# as a lexeme.
I can't see an obviously good workaround for this. The library can't change with different GHC flags. Alternatives:
When GHC does 'Show' for a constructor A#, make it spit out some funny escape sequence like A_hash. (And dually for reading.) But that is no fun. The ASCII in the file would look odd to a human, and human-written stuff like A# would fail.
Simply fix Text.Reader.Lex to recognise a postfix hash as a legal lexeme. The downside here is that lex ought to parse a+x#c as five single-character lexemes, so we'd be changing the behaviour away from H98.
Like the previous idea, but make a copy of Text.Reader.Lex and invoke that when building derived Read instances. The original lex would stay unchanged. In effect we'd just have a new function lexWithTrailingHashes. Actually you would not need to copy all of it, by a long chalk; but there'd be a little duplication.
My suggestion would be to follow the third plan. Anyone who cares, feel free to express an opinion.
Once we've decided, executing the fix should be easy, so I'll milestone for 7.2
commit bf0d3df4d011bc93af28b195a97abfcd24b9e7d6Author: simonpj <simonpj@cam-04-unx.europe.corp.microsoft.com>Date: Tue Apr 19 13:31:53 2011 +0100 Fix Trac #5041: parse the trailing '#' This matters for constructors and field labels that have a trailing hash (MagicHash language extension). compiler/typecheck/TcGenDeriv.lhs | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-)
That's right. If you look at the discussion thread above we decided that allowing the space fixed your problem without making an invasive change to the libraries. It's too liberal as you note, but it's not getting in anyone's way (as far as I know). Until it does it's not worth the effort to fix it properly (unless someone wants to volunteer).
Still, fair enough, it's still wrong so I'll leave it open with milestone bottom