= modify (\vs->[(ident, Func (length as) [] \e->zipSt sub as e body):vs])
>>| eval rest
eval (Lit v) = pure v
-eval (Var v) = gets (lookup v)
- >>= maybe (err ("Variable " +++ toString v +++ " not found")) pure
+eval (Var v) = gets (lookup v) >>= maybe (err (toString v +++ " not found")) pure
eval (App e1 e2) = eval e1 >>= \v->case v of
- (Func 0 a b) = err ("Saturated function: : " +++ toString e1)
+// (Func 0 a b) = err ("Saturated function: : " +++ toString e1)
(Func n as b) = pure (Func (n-1) (as ++ [e2]) b)
- _ = err ("Cannot apply " +++ toString e2 +++ " to " +++ toString e1)
+// _ = err ("Cannot apply " +++ toString e2 +++ " to " +++ toString e1)
eval (Lambda a b) = pure (Func 1 [] (\[arg]->sub a arg b))
eval (Builtin i as) = case (i, as) of
(['if'], [p,t,e]) = eval p >>= printer >>= \v->case v of
(<:>) l r = (\xs->[l:xs]) <$> r
:: Token = TTEq | TTSemiColon | TTLambda | TTDot | TTBrackOpen | TTBrackClose | TTBool Bool | TTInt Int | TTOp [Char] | TTIdent [Char]
+
derive gEq Token
-instance toString Token where toString t = printToString t
derive gPrint Token
+
+instance toString Token where toString t = printToString t
+
lex :: [Char] -> Either [String] [Token]
lex [] = pure []
lex [';':ts] = TTSemiColon <:> lex ts
(map fst $ sortBy (on (<) snd) ifxs)
$ pChainl (pure App)
$ Lambda <$ pToken TTLambda <*> pId <* pToken TTDot <*> pExpression
+ <|> Var <$ pToken TTBrackOpen <*> pOp <* pToken TTBrackClose
<|> pToken TTBrackOpen *> pExpression <* pToken TTBrackClose
- <|> Lit o Int <$> (\(TTInt i)->i) <$> pTop ? (\t->t=:(TTInt _))
+ <|> (\(TTInt i)->Lit (Int i)) <$> pTop ? (\t->t=:(TTInt _))
<|> (\(TTBool i)->Lit (Bool i)) <$> pTop ? (\t->t=:(TTBool _))
<|> Var <$> pId