decimal is an Attoparsec parser with type Integral a => Parser a. It reads decimal integer input and produces a result in the requested integral type, such as Integer or Word16. section 12.2.2
Parsing PNM header dimensions
A PNM header parser uses C8.decimal for width and height, and optionally for maxVal. The surrounding parser skips whitespace and comments before each value. section 12.2.2
Listing 12.23 A parser for PNM headers with Attoparsec
headerP :: Parser Header
headerP = do
skipWhitespace
magicNumber <-
choice #1
[ magicNumberP1P,
magicNumberP2P,
magicNumberP3P,
magicNumberP4P,
magicNumberP5P,
magicNumberP6P
]
skipWhitespace
width <- C8.decimal #2
skipWhitespace
height <- C8.decimal #2
maxVal <- do
if magicNumber == P1 || magicNumber == P4
then return Nothing
else Just <$> (skipWhitespace *> C8.decimal) #3
whitespace
return Header {..}
See decimal used inside a complete Attoparsec parser for PNM headers, including polymorphic numeric fields and conditional maxVal parsing. section 12.2.2
