generalize the filter function

This commit is contained in:
Krasimir Angelov committed 2026-10-15 15:09:07 +02:00
1 parent 44a7f1bf7a
commit 7b10bee627
2 files changed
+36 -21

No files matched your search

+21 -9
View File
@@ -1037,15 +1037,21 @@ value2termM flat xs (VReset ctl mb_cv v mb_qid) = do
select n (t:ts) = select (n-1) ts
_ -> evalError (pp "[select: .. | ..] requires an integer constant")
| ctl == cFilter =
let filter [] = mzero
filter (t:ts) =
case t of
R rs -> case (lookup (ident2label cp1) rs, lookup (ident2label cp2) rs) of
(Just (_,t), Just (_,Q q))
| q == (cPredef,cTrue) -> pure t `mplus` filter ts
_ -> filter ts
_ -> evalError (pp "The term must be a record")
in filter ts
case mb_cv of
Nothing -> let filter [] = mzero
filter (t:ts) =
case t of
R rs -> case (lookup (ident2label cp1) rs, lookup (ident2label cp2) rs) of
(Just (_,t), Just (_,Q q))
| q == (cPredef,cTrue) -> pure t `mplus` filter ts
_ -> filter ts
_ -> evalError (pp "The term must be a record")
in filter ts
Just cv -> do cts <- reset (value2termM True xs cv)
case ts \\ cts of
[] -> mzero
[t] -> return t
ts -> return (FV ts)
| ctl == cDefault =
case (ts,mb_cv) of
([] ,Nothing) -> mzero
@@ -1054,6 +1060,12 @@ value2termM flat xs (VReset ctl mb_cv v mb_qid) = do
| ctl == cList =
case (ts,mb_cv) of
([], _) -> mzero
([FV ts],Just cv) ->
do let Just (mn,id) = mb_qid
cat = showIdent id
ct <- value2termM flat xs cv
t <- listify mn cat ts
return (App (App (QC (mn,identS ("Conj"++cat))) ct) t)
([t], _) -> return t
(ts,Just cv) ->
do let Just (mn,id) = mb_qid
+15 -12
View File
@@ -526,19 +526,22 @@ tcRho scope c (Reset ctl mb_ct t qid) mb_ty
Nothing -> evalError (pp "[select: .. | ..] requires an integer argument")
(t,_) <- tcRho scope c1 t (Just rec_ty)
return (Reset ctl mb_ct t qid,ty)
| ctl == cFilter = concreteOnly "Control operators" $ do
ty <- case mb_ty of
Just ty -> return ty
Nothing -> do i <- newResiduation scope
return (VMeta i [])
let rec_ty = VRecType [ (ident2label cp1, True, ty)
, (ident2label cp2, True, VApp (cPredef,cBool) [])
] False
| ctl == cFilter = concreteOnly "Control operators" $
case mb_ct of
Just ct -> evalError (pp "[filter | ..] cannot take an argument")
Nothing -> return ()
(t,_) <- tcRho scope c t (Just rec_ty)
return (Reset ctl mb_ct t qid,ty)
Just ct -> do
(ct,ty) <- tcRho scope c ct mb_ty
(t, ty) <- tcRho scope c t (Just ty)
return (Reset ctl (Just ct) t qid,ty)
Nothing -> do
ty <- case mb_ty of
Just ty -> return ty
Nothing -> do i <- newResiduation scope
return (VMeta i [])
let rec_ty = VRecType [ (ident2label cp1, True, ty)
, (ident2label cp2, True, VApp (cPredef,cBool) [])
] False
(t,_) <- tcRho scope c t (Just rec_ty)
return (Reset ctl mb_ct t qid,ty)
| ctl == cDefault = concreteOnly "Control operators" $ do
let (c1,c2) = split c
(t,ty) <- tcRho scope c1 t mb_ty