summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lacweb.grm21
-rw-r--r--src/lacweb.lex1
-rw-r--r--tests/eargs.lac8
-rw-r--r--tests/recBad.lac2
4 files changed, 28 insertions, 4 deletions
diff --git a/src/lacweb.grm b/src/lacweb.grm
index 2e328891..87fa4655 100644
--- a/src/lacweb.grm
+++ b/src/lacweb.grm
@@ -151,7 +151,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
| LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
| EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
| DIVIDE | DOTDOTDOT
- | CON | LTYPE | VAL | REC | AND | FOLD | UNIT | KUNIT | CLASS
+ | CON | LTYPE | VAL | REC | AND | FUN | FOLD | UNIT | KUNIT | CLASS
| DATATYPE | OF
| TYPE | NAME
| ARROW | LARROW | DARROW | STAR
@@ -177,6 +177,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
| decl of decl
| vali of string * con option * exp
| valis of (string * con option * exp) list
+ | copt of con option
| dargs of string list
| barOpt of unit
@@ -230,6 +231,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
| eargp of exp * con -> exp * con
| eargs of exp * con -> exp * con
| eargl of exp * con -> exp * con
+ | eargl2 of exp * con -> exp * con
| branch of pat * exp
| branchs of (pat * exp) list
@@ -319,6 +321,7 @@ decl : CON SYMBOL cargl2 kopt EQ cexp (let
| _ => raise Fail "Arguments specified for imported datatype")
| VAL vali (DVal vali, s (VALleft, valiright))
| VAL REC valis (DValRec valis, s (VALleft, valisright))
+ | FUN valis (DValRec valis, s (FUNleft, valisright))
| SIGNATURE CSYMBOL EQ sgn (DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
| STRUCTURE CSYMBOL EQ str (DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))
@@ -365,8 +368,17 @@ dcons : dcon ([dcon])
dcon : CSYMBOL (CSYMBOL, NONE)
| CSYMBOL OF cexp (CSYMBOL, SOME cexp)
-vali : SYMBOL EQ eexp (SYMBOL, NONE, eexp)
- | SYMBOL COLON cexp EQ eexp (SYMBOL, SOME cexp, eexp)
+vali : SYMBOL eargl2 copt EQ eexp (let
+ val loc = s (SYMBOLleft, eexpright)
+ val t = Option.getOpt (copt, (CWild (KType, loc), loc))
+
+ val (e, t) = eargl2 (eexp, t)
+ in
+ (SYMBOL, SOME t, e)
+ end)
+
+copt : (NONE)
+ | COLON cexp (SOME cexp)
valis : vali ([vali])
| vali AND valis (vali :: valis)
@@ -581,6 +593,9 @@ eargs : earg (earg)
eargl : eargp eargp (eargp1 o eargp2)
| eargp eargl (eargp o eargl)
+eargl2 : (fn x => x)
+ | eargp eargl2 (eargp o eargl2)
+
earg : SYMBOL kcolon kind (fn (e, t) =>
let
val loc = s (SYMBOLleft, kindright)
diff --git a/src/lacweb.lex b/src/lacweb.lex
index 5ba2f5c8..b7459675 100644
--- a/src/lacweb.lex
+++ b/src/lacweb.lex
@@ -274,6 +274,7 @@ notags = [^<{\n]+;
<INITIAL> "val" => (Tokens.VAL (pos yypos, pos yypos + size yytext));
<INITIAL> "rec" => (Tokens.REC (pos yypos, pos yypos + size yytext));
<INITIAL> "and" => (Tokens.AND (pos yypos, pos yypos + size yytext));
+<INITIAL> "fun" => (Tokens.FUN (pos yypos, pos yypos + size yytext));
<INITIAL> "fn" => (Tokens.FN (pos yypos, pos yypos + size yytext));
<INITIAL> "fold" => (Tokens.FOLD (pos yypos, pos yypos + size yytext));
<INITIAL> "case" => (Tokens.CASE (pos yypos, pos yypos + size yytext));
diff --git a/tests/eargs.lac b/tests/eargs.lac
index d4d6fdf4..bfac497a 100644
--- a/tests/eargs.lac
+++ b/tests/eargs.lac
@@ -3,3 +3,11 @@ val id2 = fn n => id1 n
val pair1 = fn (t1 ::: Type) (t2 ::: Type) (x1 : t1) (x2 : t2) => (x1, x2)
val pair2 = fn (t1 ::: Type) (t2 ::: Type) (x1 : t1) (x2 : t2) () => pair1 x1 x2
+
+val id3 n = id2 n
+val id4 n : int = id3 n
+val id5 (n : int) = id4 n
+val id6 (n : int) : int = id5 n
+
+val id1 (t ::: Type) (x : t) = x
+val id2 (t ::: Type) (x : t) : t = id1 x
diff --git a/tests/recBad.lac b/tests/recBad.lac
index 8d844efb..11934ec0 100644
--- a/tests/recBad.lac
+++ b/tests/recBad.lac
@@ -1,6 +1,6 @@
datatype list a = Nil | Cons of a * list a
-val rec append : t ::: Type -> list t -> list t -> list t = fn t ::: Type => fn ls1 => fn ls2 =>
+fun append (t ::: Type) (ls1 : list t) (ls2 : list t) : list t =
case ls1 of
Nil => ls2
| Cons (h, t) => Cons (h, append t ls2)