{-

A simpler definition of truncation ∥ A ∥ n from n ≥ -1

Note that this uses the HoTT book's indexing, so it will be off
 from `∥_∥_` in HITs.Truncation.Base by -2

-}
{-# OPTIONS --safe #-}
module Cubical.HITs.Truncation.Base where

open import Cubical.Data.NatMinusOne
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Pointed
open import Cubical.HITs.Sn.Base
open import Cubical.Data.Nat.Base
open import Cubical.Data.Unit.Base
open import Cubical.Data.Empty

-- this definition is off by one. Use hLevelTrunc or ∥_∥ for truncations
-- (off by 2 w.r.t. the HoTT-book)
data HubAndSpoke {} (A : Type ) (n : ) : Type  where
  ∣_∣ : A  HubAndSpoke A n
  hub : (f : S₊ n  HubAndSpoke A n)  HubAndSpoke A n
  spoke : (f : S₊ n  HubAndSpoke A n) (x : S₊ n)  hub f  f x

hLevelTrunc :  {} (n : ) (A : Type )  Type 
hLevelTrunc zero A = Unit*
hLevelTrunc (suc n) A = HubAndSpoke A n

∥_∥_ :  {} (A : Type ) (n : )  Type 
 A  n = hLevelTrunc n A

∣_∣ₕ :  {} {A : Type } {n : }  A   A  n
∣_∣ₕ {n = zero} a = tt*
∣_∣ₕ {n = suc n} a =  a 

-- Pointed version
hLevelTrunc∙ :  {} (n : ) (A : Pointed )  Pointed 
fst (hLevelTrunc∙ n A) = hLevelTrunc n (typ A)
snd (hLevelTrunc∙ zero A) = tt*
snd (hLevelTrunc∙ (suc n) A) =  pt A ∣ₕ