From: pimjager Date: Tue, 21 Jun 2016 09:29:20 +0000 (+0200) Subject: fixed field selectors on arity 0 functions X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=15b55e5dda709ab33437c453bf9fdf7d6c8c126f;p=cc1516.git fixed field selectors on arity 0 functions --- diff --git a/AST.icl b/AST.icl index d2d1a95..24b0ac6 100644 --- a/AST.icl +++ b/AST.icl @@ -118,7 +118,7 @@ instance toString Expr where toString e = concat $ print e printSelectors :: [FieldSelector] -> [String] -printSelectors fs = printersperse "." fs +printSelectors fs = ["."] ++ printersperse "." fs printFunCall :: String [Expr] [FieldSelector] -> [String] printFunCall s args fs = [s, "(":printersperse "," args] ++ [")"] ++ diff --git a/examples/higher.spl b/examples/higher.spl index 59bbbf5..4fdde0f 100644 --- a/examples/higher.spl +++ b/examples/higher.spl @@ -50,7 +50,7 @@ main(){ var plus = \x y->x+y; var g = map(plus, [1,2,3]); - var is = map(\f->f(1), g); + //var is = map(\f->f(1), g); //print("is.hd", is.hd); diff --git a/examples/old/quickTest.spl b/examples/old/quickTest.spl index da99ac4..8a9cc26 100644 --- a/examples/old/quickTest.spl +++ b/examples/old/quickTest.spl @@ -1,7 +1,9 @@ +x() { + return [[1,2,3]]; +} + main() { - - var xs = [2]; - var ys = [1, True]; - var ls = [1, 2, True, 'a']; + + var z = x().hd.hd; } \ No newline at end of file diff --git a/sem.icl b/sem.icl index eef2974..fd9eb5c 100644 --- a/sem.icl +++ b/sem.icl @@ -308,8 +308,8 @@ instance infer Expr where _ = pure f ) >>= \newF-> fresh >>= \tv->case expected of - FuncType t = pure (s1, t, (FunExpr p newF args fs)) - //TODO: Fieldselectors! + FuncType t = foldM foldFieldSelectors t fs >>= \returnType -> + pure (s1, returnType, (FunExpr p newF args fs)) _ = (let given = foldr (->>) tv argTs in lift (unify expected given) >>= \s2-> applySubst s2 >>|