From: pimjager Date: Tue, 21 Jun 2016 09:12:04 +0000 (+0200) Subject: Fixed checking of lists X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=81a27334bdf38fbad6d4e8804abbf0c7db5fac7b;p=cc1516.git Fixed checking of lists --- diff --git a/examples/old/quickTest.spl b/examples/old/quickTest.spl new file mode 100644 index 0000000..da99ac4 --- /dev/null +++ b/examples/old/quickTest.spl @@ -0,0 +1,7 @@ +main() { + + var xs = [2]; + var ys = [1, True]; + var ls = [1, 2, True, 'a']; + +} \ No newline at end of file diff --git a/sem.icl b/sem.icl index a65bef6..eef2974 100644 --- a/sem.icl +++ b/sem.icl @@ -199,11 +199,11 @@ unify t1 t2=:(IdType tv) | t1 == (IdType tv) = Right zero | otherwise = Right $ 'Map'.singleton tv t1 unify t1=:(IdType tv) t2 = unify t2 t1 unify (ta1->>ta2) (tb1->>tb2) = unify ta1 tb1 >>= \s1-> - unify ta2 tb2 >>= \s2-> - Right $ compose s1 s2 + unify (subst s1 ta2) (subst s1 tb2) >>= \s2-> + Right $ compose s2 s1 unify (TupleType (ta1,ta2)) (TupleType (tb1,tb2)) = unify ta1 tb1 >>= \s1-> unify ta2 tb2 >>= \s2-> - Right $ compose s1 s2 + Right $ compose s2 s1 unify (ListType t1) (ListType t2) = unify t1 t2 unify (FuncType t1) (FuncType t2) = unify t1 t2 unify t1 t2 | t1 == t2 = Right zero @@ -269,21 +269,26 @@ instance infer Expr where let given = t1 ->> t2 ->> tv in op2Type op >>= \expected -> lift (unify expected given) >>= \s3 -> + applySubst s3 >>| pure ((compose s3 $ compose s2 s1), subst s3 tv, Op2Expr p e1_ op e2_) Op1Expr p op e1 = infer e1 >>= \(s1, t1, e1_) -> + applySubst s1 >>| fresh >>= \tv -> let given = t1 ->> tv in op1Type op >>= \expected -> lift (unify expected given) >>= \s2 -> + applySubst s2 >>| pure (compose s2 s1, subst s2 tv, Op1Expr p op e1) - EmptyListExpr _ = (\tv->(zero,tv,e)) <$> fresh + EmptyListExpr _ = (\tv->(zero,ListType tv,e)) <$> fresh TupleExpr p (e1, e2) = infer e1 >>= \(s1, t1, e1_) -> + applySubst s1 >>| infer e2 >>= \(s2, t2, e2_) -> + applySubst s2 >>| pure (compose s2 s1, TupleType (t1,t2), TupleExpr p (e1_,e2_)) LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be Unfolded" @@ -292,6 +297,7 @@ instance infer Expr where lookup f >>= \expected -> let accST = (\(s,ts,es) e->infer e >>= \(s_,et,e_)-> pure (compose s_ s,ts++[et],es++[e_])) in foldM accST (zero,[],[]) args >>= \(s1, argTs, args_)-> + applySubst s1 >>| (case f of "print" = case head argTs of IntType = pure "1printint" @@ -306,6 +312,7 @@ instance infer Expr where //TODO: Fieldselectors! _ = (let given = foldr (->>) tv argTs in lift (unify expected given) >>= \s2-> + applySubst s2 >>| let fReturnType = subst s2 tv in foldM foldFieldSelectors fReturnType fs >>= \returnType -> pure (compose s2 s1, returnType, FunExpr p newF args_ fs))