Mercurial > urweb
changeset 22:d8850cc06d24
Reducing known record projections
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 08 Jun 2008 16:08:31 -0400 |
parents | 067029c748e9 |
children | bfa2e9ae4df8 |
files | src/reduce.sml tests/reduce.lac |
diffstat | 2 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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"}