\import Equiv
\import Homotopy.Pointed
\import Homotopy.Pushout
\import Paths

\func Susp (A : \Type) => PushoutData {A} (\lam _ => ()) (\lam _ => ())
  \where {
    \func rec {A B : \Type} (b1 b2 : B) (f : A -> b1 = b2) (x : Susp A) : B \elim x
      | north => b1
      | south => b2
      | pglue a => f a
      \where
        -- | The universal property of the suspension.
        \func equiv {A B : \Type}
          : QEquiv {\Sigma (b1 b2 : B) (A -> b1 = b2)} {Susp A -> B} (\lam t => rec t.1 t.2 t.3) (\lam h => (h north, h south, \lam a => pmap h (pmerid a))) \cowith
          | ret_f _ => idp
          | f_sec h => path \lam i x => (\case \elim x \return rec (h north) (h south) (\lam a => pmap h (pmerid a)) x = h x \with {
            | pinl _ => idp
            | pinr _ => idp
            | pglue _ _ => idp
          }) i

    \func map {A B : \Type} (f : A -> B) : Susp A -> Susp B
      => rec north south (\lam a => pmerid (f a))

    \func pointed (A : \Type) => \new Pointed (Susp A) north

    \func pushout.{u} (A : \Type u) => pushoutData {A} (\lam _ => ()) (\lam _ => ())
  }

\func Susp-Func {X Y : Pointed} (f : X ->* Y) : Susp.pointed X ->* Susp.pointed Y
  => (Susp.map f.1, idp)

\cons north {A : \Type} : Susp A => pinl ()

\cons south {A : \Type} : Susp A => pinr ()

\func pmerid {A : \Type} (a : A) : north = south => path (pglue a)