+// t = Function ['start'] [] (Lit (Int 42))
+ t =
+ [Function ['id'] [] (Lit (Int 42))
+ ,Function ['start'] [] (App (Var ['id']) (Lit (Int 42)))
+ ]
+
+check :: AST -> Either [String] AST
+check (AST fs) = case sortBy (on (>) isStart) fs of
+ [(Function ['start'] as _):rest]
+ = case runRWST (infer (TypeEnv 'DM'.newMap) fs) [] {tiSupply=0,tiSubst='DM'.newMap} of
+ Left e = Left e
+ Right _ = Right (AST fs)
+ _ = Left ["No start function defined"]
+where
+ isStart a = a=:(Function ['start'] [] _)