,(['_mul'], Forall [] $ TInt --> TInt --> TInt)
,(['_add'], Forall [] $ TInt --> TInt --> TInt)
,(['_sub'], Forall [] $ TInt --> TInt --> TInt)
+ ,(['_div'], Forall [] $ TInt --> TInt --> TInt)
]
makeExpression :: [Function] Expression -> Expression
-makeExpression fs start = foldr mkExpr start $ scc [(l, vars e [])\\(l, e)<-nicefuns]
+makeExpression fs start = foldr mkExpr start $ scc $ map (appSnd vars) nicefuns
where
mkExpr :: [[Char]] -> (Expression -> Expression)
mkExpr scc = Let [(l, e)\\(l, e)<-nicefuns, s<-scc | s == l]
nicefuns :: [([Char], Expression)]
- nicefuns = [(l, foldr (\x c->Lambda x o c) id i e)\\(Function l i e)<-fs]
-
- vars :: Expression [[Char]] -> [[Char]]
- vars (Var v=:[m:_]) c = [v:c]
- vars (App l r) c = vars l $ vars r c
- vars (Lambda l e) c = [v\\v<-vars e c | v <> l]
- vars (Let ns e) c = flatten
- [ [v\\v<-vars e c | not (isMember v (map fst ns))]
- : map (\(i, e)->[v\\v<-vars e [] | v <> i]) ns]
- vars _ c = c
+ nicefuns = [(l, foldr ((o) o Lambda) id i e)\\(Function l i e)<-fs]
+
+ vars :: Expression -> [[Char]]
+ vars (Var v) = [v]
+ vars (App l r) = vars l ++ vars r
+ vars (Lambda l e) = flt l e
+ vars (Let ns e) = flatten [[v\\v<-vars e | not (isMember v (map fst ns))]:map (uncurry flt) ns]
+ vars _ = []
+
+ flt i e = [v\\v<-vars e | v <> i]
instance toString Scheme where
toString (Forall [] t) = toString t