As part of the 4th exercise here, I would like to use a function like reads type readHex with the Parser parseq.
For this, I wrote a function:
liftReadsToParse :: Parser String -> (String -> [(a, String)]) -> Parser a liftReadsToParse pf = p >>= \s -> if null (fs) then fail "No parse" else (return . fst . head ) (fs)
What can be used, for example, in GHCI, for example:
*Main Numeric> parse (liftReadsToParse (many1 hexDigit) readHex) "" "a1" Right 161
Can anyone suggest any improvement to this approach regarding:
Will the term
(fs) be remembered or evaluated twice in the case of
null (fs) returning
False ? Processing several successful parses, i.e. when
length (fs) greater than one, I donβt know how this par par is sorted. Processing the rest of the syntax, i.e.
(snd . head) (fs) .
source share