|
|
|
|
|
by stevan
4030 days ago
|
|
I'd disagree with the two statements: > People who think they understand something about the theory of programming languages, including me, tend to agree that what Python does is wrong. > In fact you can program heterogeneous lists in dependently typed languages, but it’s unreasonably complicated. Here's some Agda code that shows that both heterogeneous if statements and lists make sense and are easy to work with in type theory. data Bool : Set where
true false : Bool
if : ∀ {ℓ} {P : Bool → Set ℓ} (b : Bool) → P true → P false → P b
if true t f = t
if false t f = f
postulate Char : Set
{-# BUILTIN CHAR Char #-}
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
ex₁ : ℕ
ex₁ = if {P = λ b → if b ℕ Char} true 0 'a'
infixr 5 _∷_
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : A → List A → List A
data HList : List Set → Set where
[] : HList []
_∷_ : ∀ {A As} → A → HList As → HList (A ∷ As)
ex₂ : HList (ℕ ∷ Char ∷ (ℕ → ℕ) ∷ [])
ex₂ = 1 ∷ 'a' ∷ suc ∷ []
|
|