# HG changeset patch # User Adam Chlipala # Date 1212955711 14400 # Node ID d8850cc06d24759c4089cb8baf3995f1ab3008f1 # Parent 067029c748e94e92a37deed5f2765542352016ac Reducing known record projections diff -r 067029c748e9 -r d8850cc06d24 src/reduce.sml --- a/src/reduce.sml Sun Jun 08 16:02:26 2008 -0400 +++ b/src/reduce.sml Sun Jun 08 16:08:31 2008 -0400 @@ -144,6 +144,12 @@ | ECApp ((ECAbs (_, _, e1), loc), c) => #1 (reduceExp env (subConInExp (0, c) e1)) + | EField ((ERecord xes, _), (CName x, _), _) => + (case List.find (fn ((CName x', _), _) => x' = x + | _ => false) xes of + SOME (_, e) => #1 e + | NONE => e) + | _ => e and reduceExp env = U.Exp.mapB {kind = kind, con = con, exp = exp, bind = bind} env diff -r 067029c748e9 -r d8850cc06d24 tests/reduce.lac --- a/tests/reduce.lac Sun Jun 08 16:02:26 2008 -0400 +++ b/tests/reduce.lac Sun Jun 08 16:08:31 2008 -0400 @@ -14,7 +14,12 @@ con c6 = apply id int con c7 = apply (fst int) string -val grab = fn n :: Name => fn t :: Type => fn fs :: {Type} => +val tickle = fn n :: Name => fn t :: Type => fn fs :: {Type} => fn x : $([n = t] ++ fs) => x -val grabA = grab[#A][int][[B = string]] -val test_grabA = grabA {A = 6, B = "13"} +val tickleA = tickle[#A][int][[B = string]] +val test_tickleA = tickleA {A = 6, B = "13"} + +val grab = fn n :: Name => fn t ::: Type => fn fs ::: {Type} => + fn x : $([n = t] ++ fs) => x.n +val test_grab1 = grab[#A] {A = 6, B = "13"} +val test_grab2 = grab[#B] {A = 6, B = "13"}