A question about using Parsing.hs in the standard lab:
We're quite confused as how to write parsers for the simplest expressions. Since a lot of the functions in the parsing library that were described in your lecture videos have been excluded (success, >*>, pmap, etc.), it's hard to come up with these simple functions.
readsP is especially confusing.
We have no problem parsing a number from the command line (parse readsP "123.456hej" :: Maybe (Double,String)), but how would we write a function for a parser which achieves this, AND uses Num on the result (really wish we had pmap here)?
There were some changes to the Parsing module for 2015, but we did not remove any functionality, we just removed stuff that is available from the type classes Monad and Functor.
If you only saw the online lectures then you should note that pmap and >*> are
available as fmap (from class Functor) and (>>=) (from class Monad).
Regarding readsP this is an addition to the module that should make things easier, but you are not required to use it.
For example if you want to read a coordinate “(0.1,3.2)..."
coordinateParser :: Parser (Float,Float)
coordinateParser = do
char '('
x <- readsP
char ','
y <- readsP
char ')'
return (x,y)
Hope that helps.