module Prelude where
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
sym : ∀ {A} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {A} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
cong : ∀ {A B} (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
cong₂ : ∀ {A B C} (f : A → B → C) {x y u v} →
x ≡ y → u ≡ v → f x u ≡ f y v
cong₂ f refl refl = refl
data Unit : Set where
unit : Unit
data Maybe (A : Set) : Set where
just : A → Maybe A
nothing : Maybe A
infixl 4 _<$>_ _⊛_
_⊛_ : ∀ {A B} → Maybe (A → B) → Maybe A → Maybe B
just f ⊛ just x = just (f x)
just f ⊛ nothing = nothing
nothing ⊛ _ = nothing
_<$>_ : ∀ {A B} → (A → B) → Maybe A → Maybe B
f <$> x = just f ⊛ x
FromJust : ∀ A → Maybe A → Set
FromJust A (just _) = A
FromJust A nothing = Unit
fromJust : ∀ {A} (x : Maybe A) → FromJust A x
fromJust (just x) = x
fromJust nothing = unit
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
data Fin : ℕ → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
infix 5 _≟-Fin_
_≟-Fin_ : ∀ {n} (i j : Fin n) → Maybe (i ≡ j)
zero ≟-Fin zero = just refl
suc i ≟-Fin suc j = cong suc <$> i ≟-Fin j
_ ≟-Fin _ = nothing
infixr 5 _∷_
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
infixr 5 _++_
_++_ : ∀ {A} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
lookup : ∀ {A n} → Fin n → Vec A n → A
lookup zero (x ∷ xs) = x
lookup (suc i) (x ∷ xs) = lookup i xs