6464 aEquivHelper i ns1 (EListLit tx xs) ns2 (EListLit ty ys)
6565 = aEquivMaybe i ns1 tx ns2 ty &&
6666 aEquivList i ns1 xs ns2 ys
67+ aEquivHelper i ns1 (EListAppend w x) ns2 (EListAppend y z)
68+ = aEquivHelper i ns1 w ns2 y &&
69+ aEquivHelper i ns1 x ns2 z
6770 aEquivHelper _ _ _ _ _ = False
6871 -- TODO check if assert/equivalent should be in here
6972
@@ -144,8 +147,9 @@ mutual
144147 | NEquivalent Neutral Normal
145148 | NAssert Neutral
146149 | NApp Neutral Normal
147- | NList Neutral
148150 | NBoolAnd Neutral Normal
151+ | NList Neutral
152+ | NListAppend Neutral Normal
149153
150154 Show Value where
151155 show (VLambda x y) = " (VLambda " ++ show x ++ " " ++ show y ++ " )"
@@ -168,6 +172,7 @@ mutual
168172 show (NAssert x) = " (NEquivalent " ++ show x ++ " )"
169173 show (NApp x y) = " (NApp " ++ show x ++ " " ++ show y ++ " )"
170174 show (NList x) = " (NList " ++ show x ++ " )"
175+ show (NListAppend x y) = " (NListAppend " ++ show x ++ " " ++ show y ++ " )"
171176 show (NBoolAnd x y) = " (NBoolAnd " ++ show x ++ " " ++ show y ++ " )"
172177
173178extendEnv : Env -> Name -> Value -> Env
@@ -215,6 +220,7 @@ data Error
215220 | ReadBackError String
216221 | SortError
217222 | AssertError String
223+ | ListAppendError String
218224
219225public export
220226Show Error where
@@ -227,6 +233,7 @@ Show Error where
227233 show (ReadBackError x) = " ReadBackError: " ++ x
228234 show SortError = " SortError"
229235 show (AssertError str) = " AssertError" ++ str
236+ show (ListAppendError str) = " ListAppendError" ++ str
230237
231238mutual
232239 partial
@@ -294,6 +301,10 @@ mutual
294301 ty' <- eval env ty
295302 vs <- mapListEither es (eval env)
296303 Right (VListLit (Just ty') vs)
304+ eval env (EListAppend x y) = do
305+ x' <- eval env x
306+ y' <- eval env y
307+ doListAppend x' y'
297308 eval env (ENaturalIsZero x)
298309 = do x' <- eval env x
299310 doNaturalIsZero x'
@@ -329,6 +340,13 @@ mutual
329340 = Right (VNeutral (VEquivalent x y) (NAssert v))
330341 doAssert x = Left (AssertError (" Assert error: " ++ show x))
331342
343+ doListAppend : Value -> Value -> Either Error Value
344+ doListAppend (VListLit x xs) (VListLit _ ys) =
345+ Right (VListLit x (xs ++ ys)) -- TODO dropping type info
346+ doListAppend (VNeutral (VList x) v) y =
347+ Right (VNeutral (VList x) (NListAppend v (Normal' (VList x) y)))
348+ doListAppend x y = Left (ListAppendError (show x ++ " " ++ show y))
349+
332350 -- fresh names
333351 nextName : Name -> Name
334352 nextName x = x ++ " '"
@@ -364,6 +382,10 @@ mutual
364382 readBackNeutral ctx (NList a) = do
365383 a' <- readBackNeutral ctx a
366384 Right (EList a')
385+ readBackNeutral ctx (NListAppend x y) = do
386+ x' <- readBackNeutral ctx x
387+ y' <- readBackNormal ctx y
388+ Right (EListAppend x' y')
367389
368390 readBackTyped : Ctx -> Ty -> Value -> Either Error Expr
369391 readBackTyped ctx (VPi dom ran) fun =
@@ -431,7 +453,7 @@ isBool ctx other = unexpected ctx "Not Bool" other
431453
432454isList : Ctx -> Value -> Either Error ()
433455isList ctx (VList x) = Right ()
434- isList ctx other = unexpected ctx " Not Bool " other
456+ isList ctx other = unexpected ctx " Not List " other
435457
436458isEquivalent : Ctx -> Value -> Either Error (Value, Value)
437459isEquivalent ctx (VEquivalent x y) = Right (x, y)
@@ -603,3 +625,9 @@ mutual
603625 mapListEither xs (\ e => check ctx e xTy)
604626 Right (xTy)
605627 synth ctx (EAssert other) = Left (AssertError (" Can't assert for expr: " ++ show other))
628+ synth ctx (EListAppend x y) = do
629+ xTy <- synth ctx x
630+ yTy <- synth ctx y
631+ isList ctx xTy
632+ convert ctx (VConst CType ) xTy yTy
633+ Right (xTy)
0 commit comments