I\'ve been playing with Haskell for about a month. For my first \"real\" Haskell project I\'m writing a parts-of-speech tagger. As part of this project I have a type called
You're abusing Read
here.
Show
and Read
are meant to print and parse valid Haskell values, to enable debugging, etc. This doesn't always perfectly (e.g. if you import Data.Map
qualified and then call show
on a Map
value, the call to fromList
isn't qualified) but it's a valid starting point.
If you want to print or parse your values to match some specific format, then use a pretty-printing library for the former and an actual parsing library (e.g. uu-parsinglib, polyparse, parsec, etc.) for the latter. They typically have much nicer support for parsing than ReadS
(though ReadP
in GHC isn't too bad).
Whilst you may argue that this isn't necessary, this is just a quick'n'dirty hack you're doing, quick'n'dirty hacks have a tendency to linger around... do yourself a favour and do it right the first time: it means there's less to re-write when you want to do it "properly" later on.