import Data.Maybe
import Text
-import ast, scc
+import ast, scc, builtin
check :: [Function] -> Either [String] (Expression, [([Char], Scheme)])
check fs
| length dups > 0 = Left ["Duplicate functions: ":[toString n\\[(Function n _ _):_]<-dups]]
= case partition (\a->a=:(Function ['start'] _ _)) fs of
([], _) = Left ["No start function defined"]
- ([Function _ [] e:_], fs) = (\x->(e, x)) <$> runInfer (infer preamble (makeExpression fs e))
+ ([Function _ [] e:_], fs) = (\x->(e, x)) <$> runInfer (infer (fromList builtin) $ makeExpression fs e)
([Function _ _ _:_], _) = Left ["Start cannot have arguments"]
makeExpression :: [Function] Expression -> Expression
toString (a --> b) = concat ["(", toString a, " -> ", toString b, ")"]
:: TypeEnv :== Map [Char] Scheme
-preamble :: TypeEnv
-preamble = fromList
- [(['_if'], Forall [['_ift']]
- $ TBool --> TVar ['_ift'] --> TVar ['_ift'] --> TVar ['_ift'])
- ,(['_eq'], Forall [['_eq']] $ TInt --> TInt --> TBool)
- ,(['_mul'], Forall [['_mul']] $ TInt --> TInt --> TInt)
- ,(['_add'], Forall [['_add']] $ TInt --> TInt --> TInt)
- ,(['_sub'], Forall [['_sub']] $ TInt --> TInt --> TInt)
- ]
:: Subst :== Map [Char] Type
:: Infer a :== StateT [Int] (WriterT [([Char], Scheme)] (Either [String])) a