Add list sugar
Some checks failed
Publish Playground / build (push) Has been cancelled
Publish Playground / deploy (push) Has been cancelled

This commit is contained in:
2026-03-29 19:30:37 -07:00
parent 2f1185bf4c
commit 4814682712
5 changed files with 53 additions and 0 deletions

View File

@@ -80,6 +80,18 @@ lookupDef ctx name = go 0 ctx.types ctx.env
go ix ((nm, ty) :: xs) (v :: vs) = if nm == name then Just v else go (1 + ix) xs vs
go ix _ _ = Nothing
expandList : FC Maybe Raw Raw
expandList fc Nothing = RVar fc "Nil"
expandList fc (Just t) = go fc t
where
cons : FC Raw Raw Raw
cons fc t u = RApp fc (RApp fc (RVar fc "_::_") t Explicit) u Explicit
go : FC Raw Raw
go fc (RApp fc' (RApp fc'' (RVar fc "_,_") t Explicit) u Explicit) =
cons fc t $ go fc u
go fc t = cons fc t (RVar fc "Nil")
forceMeta : Val -> M Val
forceMeta (VMeta fc ix sp) = do
meta <- lookupMeta ix
@@ -977,6 +989,7 @@ mkPat (RAs fc as tm, icit) = do
(PatCon fc icit nm args Nothing) => pure $ PatCon fc icit nm args (Just as)
(PatCon fc icit nm args _) => error fc "Double as pattern \{show tm}"
t => error fc "Can't put as on non-constructor \{show tm}"
mkPat (RList fc mt, icit) = mkPat (expandList fc mt, icit)
mkPat (tm, icit) = do
top <- getTop
case splitArgs tm Nil of
@@ -1538,6 +1551,8 @@ infer ctx (RVar fc nm) = go 0 ctx.types
go i ((x, ty) :: xs) = if x == nm then pure (Bnd fc i, ty)
else go (i + 1) xs
infer ctx (RList fc mt) = infer ctx $ expandList fc mt
infer ctx (RApp fc t u icit) = do
-- If the app is explicit, add any necessary metas
(icit, t, tty) <- case icit of