a = binds CTT.Pi tele' (resolveExp t)
d = lams tele' (local (insertVar f) $ resolveWhere body)
in (f,a,d,[(f,Variable)])
- DeclData (AIdent (l,f)) tele sums ->
- let tele' = flattenTele tele
- a = binds CTT.Pi tele' (return CTT.U)
- cs = [ (unAIdent lbl,Constructor) | OLabel lbl _ <- sums ]
- pcs = [ (unAIdent lbl,PConstructor) | PLabel lbl _ _ _ <- sums ]
- sum = if null pcs then CTT.Sum else CTT.HSum
- d = lams tele' $ local (insertVar f) $
- sum <$> getLoc l <*> pure f
- <*> mapM (resolveLabel (cs ++ pcs)) sums
- in (f,a,d,(f,Variable):cs ++ pcs)
+ DeclData x tele sums -> resolveDeclData x tele sums null
+ DeclHData x tele sums ->
+ resolveDeclData x tele sums (const False) -- always pick HSum
DeclSplit (AIdent (l,f)) tele t brs ->
let tele' = flattenTele tele
vars = map fst tele'
d = CTT.Undef <$> getLoc l <*> a
in (f,a,d,[(f,Variable)])
+-- Helper function to resolve data declarations. The predicate p is
+-- used to decide if we should use Sum or HSum.
+resolveDeclData :: AIdent -> [Tele] -> [Label] -> ([(Ident,SymKind)] -> Bool) ->
+ (Ident, Resolver Ter, Resolver Ter, [(Ident, SymKind)])
+resolveDeclData (AIdent (l,f)) tele sums p =
+ let tele' = flattenTele tele
+ a = binds CTT.Pi tele' (return CTT.U)
+ cs = [ (unAIdent lbl,Constructor) | OLabel lbl _ <- sums ]
+ pcs = [ (unAIdent lbl,PConstructor) | PLabel lbl _ _ _ <- sums ]
+ sum = if p pcs then CTT.Sum else CTT.HSum
+ d = lams tele' $ local (insertVar f) $
+ sum <$> getLoc l <*> pure f
+ <*> mapM (resolveLabel (cs ++ pcs)) sums
+ in (f,a,d,(f,Variable):cs ++ pcs)
+
resolveRTele :: [Ident] -> [Resolver CTT.Ter] -> Resolver CTT.Tele
resolveRTele [] _ = return []
resolveRTele (i:is) (t:ts) = do
--- /dev/null
+module hnat where
+
+import nat
+
+-- Non-standard nat:
+hdata hnat = nzero
+ | nsuc (n : hnat)
+
+-- This reduces to "hComp (hnat) nzero []"
+test0 : hnat = comp (<_> hnat) nzero []
+
+-- This reduces to "zero"
+test1 : nat = comp (<_> nat) zero []
+
+test2 : Id hnat nzero (comp (<_> hnat) nzero []) =
+ fill (<_> hnat) nzero []
+
+toNat : hnat -> nat = split
+ nzero -> zero
+ nsuc n -> suc (toNat n)
+
+fromNat : nat -> hnat = split
+ zero -> nzero
+ suc n -> nsuc (fromNat n)
+
+toNatK : (n : hnat) -> Id hnat (fromNat (toNat n)) n = split
+ nzero -> <_> nzero
+ nsuc n -> <i> nsuc (toNatK n @ i)
+
+fromNatK : (n : nat) -> Id nat (toNat (fromNat n)) n = split
+ zero -> <_> zero
+ suc n -> <i> suc (fromNatK n @ i)
+
+hnatEqNat : Id U hnat nat =
+ isoId hnat nat toNat fromNat fromNatK toNatK
+
+-- This is zero
+test3 : nat = trans hnat nat hnatEqNat test0
+
+-- This is "hComp (hnat) nzero []"
+test4 : hnat = trans nat hnat (<i> hnatEqNat @ -i) zero
+
+-- This is "hComp (hnat) (hComp (hnat) nzero []) []"
+test5 : hnat = trans hnat hnat (compId U hnat nat hnat hnatEqNat (<i> hnatEqNat @ -i)) nzero
+
+hnatSet : set hnat = subst U set nat hnat (<i> hnatEqNat @ -i) natSet
+