open import Paths

// Also known as "Interval" in the HoTT book
open data Segment
| left | right
| seg : left = right

def uniqueness (b : Segment) : left = b
| leftidp
| right\iseg i
| seg i\jseg (i  j)
def isContrSegment : isContr Segment ⇒ (_, uniqueness)

// The induction principle for Segment implies funExt. Here is a lemma.
private def funExt-lemma {A B : Type} (f g : AB) (p :  xf x = g x) : SegmentAB
// | f, g, p, left => f
// | f, g, p, right => g
| f, g, p, left, af a
| f, g, p, right, ag a
| f, g, p, seg i, ap a i

// Using theorems in MLTT and funExt-lemma to derive funExt
example def funExt' {A B : Type} (f g : AB) (p :  xf x = g x) : f = gpmap (funExt-lemma f g p) seg