import Data.Maybe
import Test.QuickCheck
-newtype Name = Name Integer
+newtype Name = Name String
deriving (Arbitrary,Eq,Ord)
instance Show Name where
- show (Name i) = 'i' : show i
+ show (Name i) = i
swapName :: Name -> (Name,Name) -> Name
swapName k (i,j) | k == i = j
instance Arbitrary Formula where
arbitrary = do
n <- arbitrary :: Gen Integer
- sized $ arbFormula (map Name [0..(abs n)])
+ sized $ arbFormula (map (\x -> Name ('?' : show x)) [0..(abs n)])
class ToFormula a where
toFormula :: a -> Formula
-- prop_invFormula phi b =
-- all (\alpha -> phi `evalFormula` alpha == Dir b) (invFormula phi b)
-testInvFormula :: [Face]
-testInvFormula = invFormula (Atom (Name 0) :/\: Atom (Name 1)) 1
+-- testInvFormula :: [Face]
+-- testInvFormula = invFormula (Atom (Name 0) :/\: Atom (Name 1)) 1
-- | Nominal
gensym :: [Name] -> Name
-gensym [] = Name 0
-gensym xs = Name (max+1)
- where Name max = maximum xs
+gensym [] = Name "?0"
+gensym xs = Name ('?' : show (max+1))
+ where max = maximum [ read x | Name ('?':x) <- xs ]
gensyms :: [Name] -> [Name]
gensyms d = let x = gensym d in x : gensyms (x : d)
Let. Exp ::= "let" "{" [Decl] "}" "in" Exp ;
Lam. Exp ::= "\\" [PTele] "->" Exp ;
-Path. Exp ::= "<" Name ">" Exp ;
+Path. Exp ::= "<" AIdent ">" Exp ;
Fun. Exp1 ::= Exp2 "->" Exp1 ;
Pi. Exp1 ::= [PTele] "->" Exp1 ;
Sigma. Exp1 ::= [PTele] "*" Exp1 ;
Disj. Formula ::= Formula "|" Formula1 ;
Conj. Formula1 ::= Formula1 "&" Formula2 ;
Neg. Formula2 ::= "-" Formula2 ;
-Atom. Formula2 ::= Name ;
+Atom. Formula2 ::= AIdent ;
coercions Formula 2 ;
-- Branches
terminator nonempty PTele "" ;
position token AIdent ((letter|'\''|'_')(letter|digit|'\''|'_')*) ;
-terminator AIdent "" ;
-
-position token Name (('?')(digit)*);
-terminator Name "" ;
\ No newline at end of file
+terminator AIdent "" ;
\ No newline at end of file
-------------------------------------------------------------------------------
-- | Resolver and environment
-data SymKind = Variable | Constructor
+data SymKind = Variable | Constructor | Name
deriving (Eq,Show)
-- local environment for constructors
insertVars :: [CTT.Binder] -> Env -> Env
insertVars = flip $ foldr insertVar
+insertName :: CTT.Binder -> Env -> Env
+insertName x = insertBinder (x,Name)
+
getLoc :: (Int,Int) -> Resolver CTT.Loc
getLoc l = CTT.Loc <$> asks envModule <*> pure l
resolveAIdent :: AIdent -> Resolver CTT.Binder
resolveAIdent (AIdent (l,x)) = (x,) <$> getLoc l
-resolveName :: Name -> Resolver C.Name
-resolveName (Name (_,n)) = return $ C.Name $ read $ tail n
+resolveName :: AIdent -> Resolver C.Name
+resolveName (AIdent (_,n)) = return $ C.Name n
resolveVar :: AIdent -> Resolver Ter
resolveVar (AIdent (l,x))
case CTT.lookupIdent x vars of
Just Variable -> return $ CTT.Var x
Just Constructor -> return $ CTT.Con x []
+ Just Name ->
+ throwError $ "Name " ++ x ++ " used as a variable at position " ++
+ show l ++ " in module " ++ modName
_ -> throwError $ "Cannot resolve variable " ++ x ++ " at position " ++
show l ++ " in module " ++ modName
Let decls e -> do
(rdecls,names) <- resolveDecls decls
CTT.mkWheres rdecls <$> local (insertBinders names) (resolveExp e)
- Path i e -> CTT.Path <$> resolveName i <*> resolveExp e
+ Path i e -> do
+ x <- resolveAIdent i
+ CTT.Path <$> resolveName i <*> local (insertName x) (resolveExp e)
AppFormula e phi -> CTT.AppFormula <$> resolveExp e <*> resolveFormula phi
resolveWhere :: ExpWhere -> Resolver Ter
resolveFormula (Disj phi psi) = C.orFormula <$> resolveFormula phi
<*> resolveFormula psi
-
resolveBranch :: Branch -> Resolver (CTT.Label,([CTT.Binder],Ter))
resolveBranch (Branch (AIdent (_,lbl)) args e) = do
binders <- mapM resolveAIdent args
VIdP a _ _ -> return $ a @@ phi\r
_ -> throwError (show e ++ " is not a path")\r
Trans p t -> case p of\r
- Path i a -> do\r
- rho <- asks env\r
- when (i `elem` support rho)\r
- (throwError $ show i ++ " is already declared")\r
- local (addSub (i,Atom i)) $ check VU a\r
- check (eval (Sub rho (i,Dir 0)) a) t\r
- return $ (eval (Sub rho (i,Dir 1)) a)\r
+ Path{} -> do\r
+ (a0,a1) <- checkPath p\r
+ check a0 t\r
+ return a1\r
_ -> do\r
b <- infer p\r
case b of\r
_ -> throwError $ "transport expects a path but got " ++ show p\r
_ -> throwError ("infer " ++ show e)\r
\r
+-- Check that a term is a path and output the source and target\r
+checkPath :: Ter -> Typing (Val,Val)\r
+checkPath (Path i a) = do\r
+ rho <- asks env\r
+ when (i `elem` support rho)\r
+ (throwError $ show i ++ " is already declared")\r
+ local (addSub (i,Atom i)) $ check VU a\r
+ return (eval (Sub rho (i,Dir 0)) a,eval (Sub rho (i,Dir 1)) a)\r
+\r
checks :: (Tele,Env) -> [Ter] -> Typing ()\r
checks _ [] = return ()\r
checks ((x,a):xas,nu) (e:es) = do\r
nil -> nil
cons x xs -> append A (reverse A xs) (cons x nil)
-Id (A : U) (a0 a1 : A) : U = IdP (<?0> A) a0 a1
+Id (A : U) (a0 a1 : A) : U = IdP (<i> A) a0 a1
-refl (A : U) (a : A) : Id A a a = <?0> a
+refl (A : U) (a : A) : Id A a a = <i> a
mapOnPath (A B : U) (f : A -> B) (a b : A)
- (p : Id A a b) : Id B (f a) (f b) = <?0> f (p @ ?0)
+ (p : Id A a b) : Id B (f a) (f b) = <i> f (p @ i)
funExt (A : U) (B : A -> U) (f g : (x : A) -> B x)
(p : (x : A) -> Id (B x) (f x) (g x)) :
- Id ((y : A) -> B y) f g = <?0> \(a : A) -> (p a) @ ?0
+ Id ((y : A) -> B y) f g = <i> \(a : A) -> (p a) @ i
idnat : nat -> nat = split
zero -> zero
singl (A : U) (a : A) : U = (x : A) * Id A a x
contrSingl (A : U) (a b : A) (p : Id A a b) :
- Id (singl A a) (a,refl A a) (b,p) = <?0> (p @ ?0,<?1> p @ ?0 & ?1)
+ Id (singl A a) (a,refl A a) (b,p) = <i> (p @ i,<j> p @ i & j)
J (A : U) (a : A) (C : (x : A) -> Id A a x -> U)
(d : C a (refl A a)) (x : A) (p : Id A a x) : C x p =