on master help sign in
Generate better record projection types

In particular, pay attention to parameters since there is no need to project in the type for these. Fixes #201 Fixes #1356

commit734a7bf52ff71ee394d010f46e7d0d4fe5e4c0ef authorEdwin Brady <ecb10@st-andrews.ac.uk> dateWed 16 Jul 2014, 14:02 (12 years ago) parenta329a4c
2 files changed+19−4
src/Idris/ElabDecls.hs+19−3 test/records003/records003.idr−1
src/Idris/ElabDecls.hs+19−3
@@ -871,15 +871,23 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
871871 let recty = getRecTy cty_imp
872872 let recty_u = getRecTy cty
873873
874+ let paramNames = getPNames recty ppos
875+
874876 -- rename indices when we generate the getter/setter types, so
875877 -- that they don't clash with the names of the projections
876878 -- we're generating
877879 let index_names_in = getRecNameMap "_in" ppos recty
878880 let recty_in = substMatches index_names_in recty
879881
880− logLvl 1 $ show (recty, ptys)
881− let substs = map (\ (n, _) -> (n, PApp fc (PRef fc n)
882− [pexp (PRef fc rec)])) ptys
882+ logLvl 3 $ show (recty, recty_u, ppos, paramNames, ptys)
883+ -- Substitute indices with projection functions, and parameters with
884+ -- the updated parameter name
885+ let substs = map (\ (n, _) ->
886+ if n `elem` paramNames
887+ then (n, PRef fc (mkp n))
888+ else (n, PApp fc (PRef fc n)
889+ [pexp (PRef fc rec)]))
890+ ptys
883891
884892 -- Generate projection functions
885893 proj_decls <- mapM (mkProj recty_in substs cimp) (zip ptys [0..])
@@ -900,6 +908,14 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
900908 isNonImp (PExp _ _ _ _, a) = Just a
901909 isNonImp _ = Nothing
902910
911+ getPNames (PApp _ _ as) ppos = getpn as ppos
912+ where
913+ getpn as [] = []
914+ getpn as (i:is) | length as > i,
915+ PRef _ n <- getTm (as!!i) = n : getpn as is
916+ | otherwise = getpn as is
917+ getPNames _ _ = []
918+
903919 tryElabDecl info (fn, ty, val)
904920 = do i <- getIState
905921 idrisCatch (do elabDecl' EAll info ty
test/records003/records003.idr−1
@@ -45,4 +45,3 @@ main = do print (record { event->organiser->name } test)
4545 print (record { organiser->age } idm_gbg)
4646 print (record { year } idm_gbg)
4747
48−