Skip to content

Commit a4f7fc1

Browse files
authored
Merge pull request #67 from anoma/terence/geb-dev-28
Checkpoint Idris-2 development
2 parents 35c840b + cc5d4f1 commit a4f7fc1

File tree

10 files changed

+1815
-133
lines changed

10 files changed

+1815
-133
lines changed

geb-idris/src/Executable/Test/Main.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main = do
4242
LanguageDef.Test.PolyCatTest.polyCatTest
4343
LanguageDef.Test.NatPrefixCatTest.natPrefixCatTest
4444
LanguageDef.Test.PolyProfunctorTest.polyProfunctorTest
45+
LanguageDef.Test.ADTCatTest.adtCatTest
4546
LanguageDef.Test.ProgFinSetTest.progFinSetTest
4647
LanguageDef.Test.SyntaxTest.languageDefSyntaxTest
4748
LanguageDef.Test.GebToposTest.gebToposTest
48-
LanguageDef.Test.ADTCatTest.adtCatTest

geb-idris/src/LanguageDef/ADTCat.idr

Lines changed: 111 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ InAtom = InTermAtom .* TAtom
20022002

20032003
public export
20042004
InNat : Nat -> TermMu -> TermMu
2005-
InNat = InAtom NAT
2005+
InNat = InAtom SL_NAT
20062006

20072007
-------------------
20082008
---- Utilities ----
@@ -2108,8 +2108,8 @@ public export
21082108
FBCObjRepAlg : FinBCObjAlgRec TermMu
21092109
FBCObjRepAlg =
21102110
MkFinBCObjAlg
2111-
(InAtom PRODUCT 0 . InProd)
2112-
(InAtom COPRODUCT 0 . InProd)
2111+
(InAtom SL_EXP 0 . InProd) -- random replacement for PRODUCT; obsolete
2112+
(InAtom SL_EXPL 0 . InProd) -- random replacement for COPRODUCT; obsolete
21132113

21142114
public export
21152115
fbcObjRep : FinBCObjMu -> TermMu
@@ -3437,48 +3437,117 @@ termToGebTerm = termCataRec termToGebTermAlg
34373437
-----------------------------------------------------
34383438
-----------------------------------------------------
34393439

3440+
--------------------
3441+
---- Definition ----
3442+
--------------------
3443+
3444+
public export
3445+
record OpFunctorPair {a : Type} (x, y : SliceObj a) where
3446+
constructor OFP
3447+
ofpOut : ParamSPF {a} x y
3448+
ofpIn : ParamSPF {a} y x
3449+
3450+
public export
3451+
ofpInAfterOut : {a : Type} -> {x, y : SliceObj a} ->
3452+
OpFunctorPair {a} x y -> ParamSPF {a} x x
3453+
ofpInAfterOut ofp = spfParamCompose (ofpIn ofp) (ofpOut ofp)
3454+
3455+
public export
3456+
ofpOutAfterIn : {a : Type} -> {x, y : SliceObj a} ->
3457+
OpFunctorPair {a} x y -> ParamSPF {a} y y
3458+
ofpOutAfterIn ofp = spfParamCompose (ofpOut ofp) (ofpIn ofp)
3459+
3460+
public export
3461+
OFPunit : {a : Type} -> {x, y : SliceObj a} -> OpFunctorPair {a} x y -> Type
3462+
OFPunit {a} {x} {y} ofp = ParamSPNatTrans (spfParamId y) (ofpOutAfterIn ofp)
3463+
3464+
public export
3465+
OFPcounit : {a : Type} -> {x, y : SliceObj a} -> OpFunctorPair {a} x y -> Type
3466+
OFPcounit {a} {x} {y} ofp = ParamSPNatTrans (ofpOutAfterIn ofp) (spfParamId y)
3467+
3468+
public export
3469+
record AdjFromUnit {a : Type} (x : SliceObj a) where
3470+
constructor AdjU
3471+
adjUsl : SliceObj a
3472+
adjUfp : OpFunctorPair {a} x adjUsl
3473+
adjUnt : OFPunit {a} adjUfp
3474+
3475+
public export
3476+
record AdjFromCounit {a : Type} (x : SliceObj a) where
3477+
constructor AdjC
3478+
adjCsl : SliceObj a
3479+
adjCfp : OpFunctorPair {a} x adjCsl
3480+
adjCnt : OFPcounit {a} adjCfp
3481+
3482+
public export
3483+
LeftAdjSet : Type -> Type -> Type
3484+
LeftAdjSet param pos =
3485+
pos -> Sigma {a=(SliceObj param)} (AdjFromUnit {a=param})
3486+
3487+
public export
3488+
RightAdjSet : Type -> Type -> Type
3489+
RightAdjSet param pos =
3490+
pos -> Sigma {a=(SliceObj param)} (AdjFromCounit {a=param})
3491+
3492+
public export
3493+
record CatFromAdj (a : Type) where
3494+
constructor CfA
3495+
cfaLeftAdjSet : Sigma {a=Type} (LeftAdjSet a)
3496+
cfaRightAdjSet : Sigma {a=Type} (RightAdjSet a)
3497+
3498+
public export
3499+
TwoCatFromAdj : Type -> Type
3500+
TwoCatFromAdj a = a -> Sigma {a=Type} CatFromAdj
3501+
34403502
-----------------
34413503
---- Product ----
34423504
-----------------
34433505

34443506
public export
3445-
DiagFunc : DepParamPolyFunc () Bool
3446-
DiagFunc = (const Unit ** const ((), Unit))
3507+
BoolCP : Type
3508+
BoolCP = Either Unit Unit
3509+
3510+
public export
3511+
DiagFunc : SlicePolyFunc () BoolCP
3512+
DiagFunc = SPFPolyDiag () BoolCP ()
34473513

34483514
public export
3449-
DiagSPF : SlicePolyFunc () Bool
3450-
DiagSPF = SPFFromDPPF DiagFunc
3515+
DiagSPF : SlicePolyFunc () BoolCP
3516+
DiagSPF = DiagFunc
34513517

34523518
public export
3453-
DiagApp : (x : Type) -> (b : Bool) -> x -> InterpDPPF DiagFunc (const x) b
3519+
DiagApp : (x : Type) -> (b : BoolCP) -> x -> InterpSPFunc DiagFunc (const x) b
34543520
DiagApp x b e = (() ** const e)
34553521

34563522
public export
34573523
diagTest : Nat -> (Nat, Nat)
3458-
diagTest n = (snd (DiagApp Nat False n) (), snd (DiagApp Nat True n) ())
3524+
diagTest n =
3525+
(snd (DiagApp Nat (Left ()) n) (), snd (DiagApp Nat (Right ()) n) ())
34593526

34603527
public export
34613528
diagTestCorrect : (n : Nat) -> diagTest n = (n, n)
34623529
diagTestCorrect n = Refl
34633530

34643531
public export
3465-
ProductFunc : SlicePolyFunc Bool ()
3466-
ProductFunc = (const Unit ** const Bool ** DPair.snd)
3532+
ProductFunc : SlicePolyFunc BoolCP ()
3533+
ProductFunc = SPFPi BoolCP
34673534

34683535
public export
3469-
IProductFunc : SliceFunctor Bool ()
3536+
IProductFunc : SliceFunctor BoolCP ()
34703537
IProductFunc = InterpSPFunc ProductFunc
34713538

34723539
public export
34733540
ProductInterp :
3474-
(x, y : Type) -> (x, y) -> IProductFunc (\b => if b then y else x) ()
3475-
ProductInterp x y (ex, ey) = (() ** \b => if b then ey else ex)
3541+
(x, y : Type) -> (x, y) ->
3542+
IProductFunc (\b => case b of Right () => y ; Left () => x) ()
3543+
ProductInterp x y (ex, ey) =
3544+
(() ** \b => case b of Right () => ey ; Left () => ex)
34763545

34773546
public export
34783547
productTest : (String, Nat) -> (String, Nat)
34793548
productTest (s, n) =
3480-
(snd (ProductInterp String Nat (s, n)) False,
3481-
snd (ProductInterp String Nat (s, n)) True)
3549+
(snd (ProductInterp String Nat (s, n)) (Left ()),
3550+
snd (ProductInterp String Nat (s, n)) (Right ()))
34823551

34833552
public export
34843553
productTestCorrect : (s : String) -> (n : Nat) -> productTest (s, n) = (s, n)
@@ -3493,11 +3562,11 @@ ProdAdjRL : PolyFunc
34933562
ProdAdjRL = PolyFuncFromUnitUnitSPF ProdAdjRLSPF
34943563

34953564
public export
3496-
ProdAdjLR : SlicePolyFunc Bool Bool
3565+
ProdAdjLR : SlicePolyFunc BoolCP BoolCP
34973566
ProdAdjLR = spfCompose DiagSPF ProductFunc
34983567

34993568
public export
3500-
prodAdjCounit : SPNatTrans ProdAdjLR (spfId Bool)
3569+
prodAdjCounit : SPNatTrans ProdAdjLR (spfId BoolCP)
35013570
prodAdjCounit =
35023571
(\_, _ => () ** \(i ** (() ** _)), () => ((() ** i) ** Refl))
35033572

@@ -3506,35 +3575,37 @@ prodAdjUnit : PolyNatTrans PFIdentityArena ProdAdjRL
35063575
prodAdjUnit = (const (() ** const ()) ** const (const ()))
35073576

35083577
public export
3509-
interpProdCounit : (x : SliceObj Bool) ->
3510-
SliceMorphism (InterpSPFunc ProdAdjLR x) (InterpSPFunc (spfId Bool) x)
3511-
interpProdCounit = InterpSPNT {f=ProdAdjLR} {g=(spfId Bool)} prodAdjCounit
3578+
interpProdCounit : (x : SliceObj BoolCP) ->
3579+
SliceMorphism (InterpSPFunc ProdAdjLR x) (InterpSPFunc (spfId BoolCP) x)
3580+
interpProdCounit = InterpSPNT {f=ProdAdjLR} {g=(spfId BoolCP)} prodAdjCounit
35123581

35133582
public export
3514-
testProdCounitObj : SliceObj Bool
3515-
testProdCounitObj b = if b then Nat else String
3583+
testProdCounitObj : SliceObj BoolCP
3584+
testProdCounitObj b = case b of Right () => Nat ; Left () => String
35163585

35173586
public export
35183587
testProdCounit :
35193588
SliceMorphism
35203589
(InterpSPFunc ProdAdjLR ADTCat.testProdCounitObj)
3521-
(InterpSPFunc (spfId Bool) ADTCat.testProdCounitObj)
3590+
(InterpSPFunc (spfId BoolCP) ADTCat.testProdCounitObj)
35223591
testProdCounit = interpProdCounit testProdCounitObj
35233592

35243593
public export
3525-
prodCounitProj : (String, Nat) -> (i : Bool) -> if i then Nat else String
3594+
prodCounitProj : (String, Nat) -> (i : BoolCP) ->
3595+
case i of Right () => Nat ; Left () => String
35263596
prodCounitProj (s, n) i =
35273597
snd
35283598
(ADTCat.testProdCounit i
3529-
((() ** const ()) ** \(() ** i') => if i' then n else s))
3599+
((() ** const ()) ** \(() ** i') =>
3600+
case i' of Right () => n ; Left () => s))
35303601
()
35313602

35323603
public export
3533-
testProdCounitProj1 : prodCounitProj ("five", 5) False = "five"
3604+
testProdCounitProj1 : prodCounitProj ("five", 5) (Left ()) = "five"
35343605
testProdCounitProj1 = Refl
35353606

35363607
public export
3537-
testProdCounitProj2 : prodCounitProj ("five", 5) True = 5
3608+
testProdCounitProj2 : prodCounitProj ("five", 5) (Right ()) = 5
35383609
testProdCounitProj2 = Refl
35393610

35403611
public export
@@ -3546,7 +3617,7 @@ interpProdUnit x ex =
35463617
(InterpPolyNT {p=PFIdentityArena} {q=ProdAdjRL}
35473618
prodAdjUnit x (() ** const ex))
35483619
in
3549-
(ipnt (False ** ()), ipnt (True ** ()))
3620+
(ipnt (Left () ** ()), ipnt (Right () ** ()))
35503621

35513622
-- L a -> b => a -> R b (`L a` and `b` are in the product category)
35523623
-- R f . nu a
@@ -3565,11 +3636,11 @@ prodRightAdjunct a b b' g = (fst . g, snd . g)
35653636
-------------------
35663637

35673638
public export
3568-
CoproductFunc : SlicePolyFunc Bool ()
3569-
CoproductFunc = (const Bool ** const Unit ** DPair.snd . DPair.fst)
3639+
CoproductFunc : SlicePolyFunc BoolCP ()
3640+
CoproductFunc = SPFSigma BoolCP
35703641

35713642
public export
3572-
CoprodAdjRL : SlicePolyFunc Bool Bool
3643+
CoprodAdjRL : SlicePolyFunc BoolCP BoolCP
35733644
CoprodAdjRL = spfCompose DiagSPF CoproductFunc
35743645

35753646
public export
@@ -3581,7 +3652,7 @@ CoprodAdjLR : PolyFunc
35813652
CoprodAdjLR = PolyFuncFromUnitUnitSPF CoprodAdjLRSPF
35823653

35833654
public export
3584-
coprodAdjUnit : SPNatTrans (spfId Bool) CoprodAdjRL
3655+
coprodAdjUnit : SPNatTrans (spfId BoolCP) CoprodAdjRL
35853656
coprodAdjUnit =
35863657
(\b, () => (() ** const b) ** \(b ** ()), (() ** ()) => (() ** Refl))
35873658

@@ -3590,20 +3661,21 @@ coprodAdjCounit : PolyNatTrans CoprodAdjLR PFIdentityArena
35903661
coprodAdjCounit = (const () ** const (const (() ** ())))
35913662

35923663
public export
3593-
ICoproductFunc : SliceFunctor Bool ()
3664+
ICoproductFunc : SliceFunctor BoolCP ()
35943665
ICoproductFunc = InterpSPFunc CoproductFunc
35953666

35963667
public export
35973668
CoproductInterp :
3598-
(x, y : Type) -> Either x y -> ICoproductFunc (\b => if b then y else x) ()
3599-
CoproductInterp x y (Left ex) = (False ** const ex)
3600-
CoproductInterp x y (Right ey) = (True ** const ey)
3669+
(x, y : Type) -> Either x y ->
3670+
ICoproductFunc (\b => case b of Right () => y ; Left () => x) ()
3671+
CoproductInterp x y (Left ex) = (Left () ** const ex)
3672+
CoproductInterp x y (Right ey) = (Right () ** const ey)
36013673

36023674
public export
36033675
coproductTest : Either String Nat -> Either String Nat
36043676
coproductTest sn with (CoproductInterp String Nat sn)
3605-
coproductTest sn | (False ** f) = Left $ f ()
3606-
coproductTest sn | (True ** f) = Right $ f ()
3677+
coproductTest sn | (Left () ** f) = Left $ f ()
3678+
coproductTest sn | (Right () ** f) = Right $ f ()
36073679

36083680
public export
36093681
coproductTestCorrect : (sn : Either String Nat) -> coproductTest sn = sn

0 commit comments

Comments
 (0)