# How to ask for a parser

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 ReadP and ReadPrec, which are equivalent to ReadS and Int -> ReadS respectively, but monadic. They are made invokable by readP_to_S and readPrec_to_S, respectively.

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 Nothing instead. 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:

# Objective

Parse a string to (some type).

# Valid inputs

A valid input consists of (some format).

# Invalid inputs

When the parser encounters (some format), the parser must be in an erroneous state. This includes:

• Returning an erroneous value

• Throwing an error

# Rules

1. When the input is neither valid nor invalid, it falls in don't care situation.

2. (blah blah blah)

Is this elaborate enough?