[ unify ] unify literals correctly

This commit is contained in:
2025-07-26 07:24:38 -07:00
parent 2d53976602
commit 0e110cd14f
3 changed files with 20 additions and 2 deletions

View File

@@ -455,6 +455,12 @@ unify env mode t u = do
xb' <- b' $$ fresh xb' <- b' $$ fresh
_<+>_ <$> unify env mode a a' <*> unify (fresh :: env) mode xb xb' _<+>_ <$> unify env mode a a' <*> unify (fresh :: env) mode xb xb'
-- TODO adds about 2kb, maybe add one more func for unifyPi?
-- or rearrange to split on first arg and then case on second (might be a good experiment)
unifyRest (VLit fc l) (VLit _ k) = if l == k
then pure neutral
else error fc "unify failed \{show l} =?= \{show k}"
unifyRest (VU _) (VU _) = pure neutral unifyRest (VU _) (VU _) = pure neutral
-- REVIEW I'd like to quote this back, but we have l that aren't in the environment. -- REVIEW I'd like to quote this back, but we have l that aren't in the environment.
unifyRest t' u' = error (getFC t') "unify failed \{show t'} =?= \{show u'} \n env is \{show env}" unifyRest t' u' = error (getFC t') "unify failed \{show t'} =?= \{show u'} \n env is \{show env}"

View File

@@ -54,9 +54,9 @@ Tm : U
data Literal = LString String | LInt Int | LChar Char data Literal = LString String | LInt Int | LChar Char
instance Show Literal where instance Show Literal where
show (LString str) = show str show (LString str) = quoteString str
show (LInt i) = show i show (LInt i) = show i
show (LChar c) = show c show (LChar c) = "'\{show c}'" -- FIXME single quote
data CaseAlt : U where data CaseAlt : U where
CaseDefault : Tm -> CaseAlt CaseDefault : Tm -> CaseAlt

12
tests/UnifyLit.newt Normal file
View File

@@ -0,0 +1,12 @@
module UnifyLit
import Prelude
test : 'x' 'x'
test = Refl
test2 : "foo" "foo"
test2 = Refl
test3 : 1 1
test3 = Refl