RE: How to implement Read instance for user defined type

That works, but is probably not what you want. You can use the lex function to parse identifiers not enclosed in quotes:
instance Read Mark where readsPrec _ str = [(Mark x, t') | ("mark",t) <- lex str, (x,t') <- reads t
I played a bit around with lex function and it seems that under certain circumstances it doesn't read the string of token properly For e.g. -- IP address *Mark> lex "192.168.0.1" [("192.168",".0.1")] -- digit + char Also lex "8021p" output is *Mark> lex "8021p" [("8021","p")] Is there any other lex variant available? Or should I switch to using Parsec library, in that case, will I still be able to use it with Read instances? If so, how? Anurag
participants (1)
-
Verma Anurag-VNF673