I am trying to write a parser in Haskell. In this I need a function that parses a string of length at least 1. I have the type declared below:
type Pname = String
but my function that I have doesn't work. The code I have is below, where sc
is my space consumer for whitespace and comments (I have been following the tutorial at https://mrkkrp.github.io/megaparsec/tutorials/parsing-simple-imperative-language.html for help with this parser):
pname :: Parser Pname
pname = (some ['a' .. 'z']) <* sc
but it gives me the error:
Couldn't match type ‘[]’
with ‘ParsecT Dec String Data.Functor.Identity.Identity’
Expected type: ParsecT
Dec String Data.Functor.Identity.Identity Char
Actual type: [Char]
In the first argument of ‘some’, namely ‘['a' .. 'z']’
In the first argument of ‘(<*)’, namely ‘(some ['a' .. 'z'])’
In the expression: (some ['a' .. 'z']) <* sc
Any ideas on why this doesn't work?
答案 0 :(得分:1)
Probably you meant to use oneOf
(or a similar function from your parser library) as in
pname = some (oneOf ['a' .. 'z']) <* sc
to turn the list of characters into a parser that accepts one of those characters.