Refer to this challenge in Sandbox.
My major language is Haskell. In Haskell, a parser (type
ReadS) is a function that inputs a
String and outputs a list of a tuple of the parsed element and the remaining string (
ReadS a = String -> [(a,String)]). When the list is empty, there is no parse. When the list has two or more elements, the parse is ambiguous.
There are also types
ReadPrec, which are equivalent to
Int -> ReadS respectively, but monadic. They are made invokable by
There is also
readEither, whose type is
String -> Either String a. It outputs an error message when there is no parse or the parse is ambiguous.
readMaybe :: String -> Maybe a does the same thing, but outputs
read :: String -> a does the same thing, but throws an error instead.
All these must be considered parsers, right? So a challenge asking for a parser should have the following format:
Parse a string to (some type).
A valid input consists of (some format).
When the parser encounters (some format), the parser must be in an errornous state. This includes:
Returning an errornous value
Throwing an error
When the input is neither valid nor invalid, it falls in don't care situation.
(blah blah blah)
Is this elaborate enough?