I play with Haskell for about a month. For my first βrealβ Haskell project, I am writing a speech part tagger. As part of this project, I have a type called Tag
, which represents a tag of a part of speech, implemented as follows:
data Tag = CC | CD | DT | EX | FW | IN | JJ | JJR | JJS ...
The above is a long list of standardized part-of-speech tags that I intentionally truncated. However, in this standard set of tags, there are two that end with a dollar sign ($): PRP $ and NNP $. Since I cannot have type constructors with $ in their name, I decided to rename them to PRPS and NNPS.
This is good and good, but I would like to read tags from strings in the lexicon and convert them to my Tag
type. Trying this fails:
instance Read Tag where readsPrec _ input = (\inp -> [((NNPS), rest) | ("NNP$", rest) <- lex inp]) input
Haskell Laker is choking on $. Any ideas how to do this?
The implementation of the show was quite simple. It would be great if there was some kind of similar strategy for Read.
instance Show Tag where showsPrec _ NNPS = showString "NNP$" showsPrec _ PRPS = showString "PRP$" showsPrec _ tag = shows tag
source share