I would like to get this parser to work. I am currently not quite sure where the error is. It is largely taken from the Parsec section of "Write you a scheme"
One more question: if it eventually works, are there any means to ensure that the string that starts with a question mark is always the last in the list?
input_text :: String
input_text = "Eval (isFib::, 1000, ?BOOL)"
data LTuple
= Command [LTuple]
| Number Integer
| String String
| Query Bool
deriving (Eq, Ord, Show)
data Command = Rd | Read | In | Take | Wr | Out | Eval
deriving (Eq, Ord, Show)
main :: IO ()
main = do
case parse lindaCmd "example" input_text of
Left err -> print err
Right res -> putStrLn $ "I parsed: '" ++ res ++ "'"
parseList :: Parser lindaTpl
parseList = liftM Command $ sepBy1 lindaCmd ( symbol "," )
lindaCmd = string "rd"
<|> string "take"
<|> string "out"
<|> string "eval"
<|> do char '('
x <- try parseList
char ')'return x
The current error message is:
test.hs:30:48:
Couldn't match expected type `ParsecT s0 u0 m0 sep0'
with actual type `String -> ParsecT s1 u1 m1 String'
In the return type of a call of `symbol'
Probable cause: `symbol' is applied to too few arguments
In the second argument of `sepBy1', namely `(symbol ",")'
In the second argument of `($)', namely
`sepBy1 lindaCmd (symbol ",")'
test.hs:38:17:
The function `char' is applied to three arguments,
but its type `Char -> ParsecT s0 u0 m0 Char' has only one
In a stmt of a 'do' block: char ')' return x
In the second argument of `(<|>)', namely
`do { char '(';
x <- try parseList;
char ')' return x }'
In the second argument of `(<|>)', namely
`string "eval"
<|>
do { char '(';
x <- try parseList;
char ')' return x }'