# HG changeset patch # User Adam Chlipala # Date 1212944412 14400 # Node ID 1e645beb3f3b4670a51ed091623b483adfbb008a # Parent f1c36df29ed7923a081eb3e36d6e3a100a1dac31 Implicit constructor arguments diff -r f1c36df29ed7 -r 1e645beb3f3b src/elaborate.sml --- a/src/elaborate.sml Sun Jun 08 12:27:08 2008 -0400 +++ b/src/elaborate.sml Sun Jun 08 13:00:12 2008 -0400 @@ -680,6 +680,43 @@ | E.Named _ => raise Fail ("Primitive type " ^ s ^ " bound at non-Type kind") end +fun typeof env (e, loc) = + case e of + L'.EPrim p => (primType env p, loc) + | L'.ERel n => #2 (E.lookupERel env n) + | L'.ENamed n => #2 (E.lookupENamed env n) + | L'.EApp (e1, _) => + (case #1 (typeof env e1) of + L'.TFun (_, c) => c + | _ => raise Fail "typeof: Bad EApp") + | L'.EAbs (x, t, e1) => (L'.TFun (t, typeof (E.pushERel env x t) e1), loc) + | L'.ECApp (e1, c) => + (case #1 (typeof env e1) of + L'.TCFun (_, _, _, c1) => subConInCon (0, c) c1 + | _ => raise Fail "typeof: Bad ECApp") + | L'.ECAbs (expl, x, k, e1) => (L'.TCFun (expl, x, k, typeof (E.pushCRel env x k) e1), loc) + + | L'.ERecord xes => (L'.TRecord (L'.CRecord (ktype, map (fn (x, e) => (x, typeof env e)) xes), loc), loc) + | L'.EField (_, _, {field, ...}) => field + + | L'.EError => cerror + +fun elabHead env (e as (_, loc)) t = + let + fun unravel (t, e) = + case hnormCon env t of + (L'.TCFun (L'.Implicit, x, k, t'), _) => + let + val u = cunif k + in + unravel (subConInCon (0, u) t', + (L'.ECApp (e, u), loc)) + end + | _ => (e, t) + in + unravel (t, e) + end + fun elabExp env (e, loc) = case e of L.EAnnot (e, t) => @@ -702,6 +739,7 @@ | L.EApp (e1, e2) => let val (e1', t1) = elabExp env e1 + val (e1', t1) = elabHead env e1' t1 val (e2', t2) = elabExp env e2 val dom = cunif ktype @@ -731,6 +769,7 @@ | L.ECApp (e, c) => let val (e', et) = elabExp env e + val (e', et) = elabHead env e' et val (c', ck) = elabCon env c in case #1 (hnormCon env et) of @@ -832,15 +871,19 @@ in checkKind env c' ck k'; - if kunifsInKind k' then - declError env (KunifsRemainKind (loc, k')) - else - (); + if ErrorMsg.anyErrors () then + () + else ( + if kunifsInKind k' then + declError env (KunifsRemainKind (loc, k')) + else + (); - if kunifsInCon c' then - declError env (KunifsRemainCon (loc, c')) - else - (); + if kunifsInCon c' then + declError env (KunifsRemainCon (loc, c')) + else + () + ); (env', (L'.DCon (x, n, k', c'), loc)) @@ -856,25 +899,28 @@ in checkCon env e' et c'; - if kunifsInCon c' then - declError env (KunifsRemainCon (loc, c')) - else - (); + if ErrorMsg.anyErrors () then + () + else ( + if kunifsInCon c' then + declError env (KunifsRemainCon (loc, c')) + else + (); - if cunifsInCon c' then - declError env (CunifsRemainCon (loc, c')) - else - (); + if cunifsInCon c' then + declError env (CunifsRemainCon (loc, c')) + else + (); - if kunifsInExp e' then - declError env (KunifsRemainExp (loc, e')) - else - (); + if kunifsInExp e' then + declError env (KunifsRemainExp (loc, e')) + else + (); - if cunifsInExp e' then - declError env (CunifsRemainExp (loc, e')) - else - (); + if cunifsInExp e' then + declError env (CunifsRemainExp (loc, e')) + else + ()); (env', (L'.DVal (x, n, c', e'), loc)) diff -r f1c36df29ed7 -r 1e645beb3f3b src/lacweb.grm --- a/src/lacweb.grm Sun Jun 08 12:27:08 2008 -0400 +++ b/src/lacweb.grm Sun Jun 08 13:00:12 2008 -0400 @@ -108,7 +108,7 @@ cexp : capps (capps) | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right)) - | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright)) + | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright)) | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right)) diff -r f1c36df29ed7 -r 1e645beb3f3b tests/impl.lac --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/impl.lac Sun Jun 08 13:00:12 2008 -0400 @@ -0,0 +1,5 @@ +val id = fn t :: Type => fn x : t => x +val id_self = id [t :: Type -> t -> t] id + +val idi = fn t ::: Type => fn x : t => x +val idi_self = idi idi