@@ -59,20 +59,20 @@ parseIdentifierAndValue = (,) <$> (C.indented *> C.identifier <* C.indented <* C
5959parseAbs :: P.Parsec String ParseState Value
6060parseAbs = do
6161 C.lexeme $ P.char '\\'
62− uncurriedAbs <|> curriedAbs
62+ args <- P.many (C.indented *> (P.try singleArg <|> manyArgs))
63+ C.lexeme $ C.indented *> P.string "->"
64+ value <- parseValue
65+ return $ toFunction args value
6366 where
64− uncurriedAbs :: P.Parsec String ParseState Value
65− uncurriedAbs = do
66− args <- C.indented *> C.parens ((C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma))
67− C.lexeme $ C.indented *> P.string "->"
68− value <- parseValue
69− return $ Abs args value
70− curriedAbs :: P.Parsec String ParseState Value
71− curriedAbs = do
72− args <- P.many1 (C.indented *> C.parseIdent)
73− C.lexeme $ C.indented *> P.string "->"
74− value <- parseValue
75− return $ foldl (\ret arg -> Abs [arg] ret) value args
67+ manyArgs :: P.Parsec String ParseState (Value -> Value)
68+ manyArgs = do
69+ args <- C.parens ((C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma))
70+ return $ Abs args
71+ singleArg :: P.Parsec String ParseState (Value -> Value)
72+ singleArg = Abs . return <$> C.parseIdent
73+ toFunction :: [Value -> Value] -> Value -> Value
74+ toFunction [] value = Abs [] value
75+ toFunction args value = foldr (($)) value args
7676
7777parseApp :: P.Parsec String ParseState Value
7878parseApp = App <$> parseValue