More Related Content
More from Roman Brovko (20)
03 - Scala. Boolean type
- 2. Boolean type
Haskell
import Prelude hiding (Bool, True, False)
data Bool = True | False
Scala
sealed trait Bool
case object True extends Bool
case object False extends Bool
Java
public interface Bool {}
public class True implements Bool {}
public class False implements Bool {}
Dmytro Mitin Boolean type
- 3. Boolean type
1 Type Formation
Γ ctx
Γ Bool : ∗
2 Constructors
Γ ctx
Γ true : Bool
Γ ctx
Γ false : Bool
3 Eliminator
Γ c1 : C Γ c2 : C
Γ, x : Bool if(x)(c1, c2) : C
x match { case True => c1; case False => c2 }
Dmytro Mitin Boolean type
- 4. Boolean type
4 Computation rules (”β-reduction“)
Γ c1 : C Γ c2 : C
Γ, x : Bool if(true)(c1, c2) ≡ c1 : C
Γ c1 : C Γ c2 : C
Γ, x : Bool if(false)(c1, c2) ≡ c2 : C
5 Uniqueness principle (”η-conversion“)
Dmytro Mitin Boolean type
- 5. ProvingGround
git clone --recursive https://github.com/siddhartha-gadgil/ProvingGround.git
cd ProvingGround
mill -i mantle.repl
import provingground.HoTT.
import provingground.induction.TLImplicits.
import shapeless.
val Bool = "Boolean" :: Type
val b = "b" :: Bool
val BoolInd = ("true" ::: Bool) |: ("false" ::: Bool) =: Bool
val tru :: fls :: HNil = BoolInd.intros
val recBB = BoolInd.rec(Bool)
val not = recBB(fls)(tru)
not(tru) == fls
val recBBB = BoolInd.rec(Bool ->: Bool)
val and = recBBB(b :-> b)(b :-> fls)
and(tru)(fls) == fls
Dmytro Mitin Boolean type