module A201607.WIP2.BasicICML.Sketch2 where

open import A201607.BasicICML.Syntax.DyadicGentzen hiding (β„• ; 𝟘 ; πŸ™) public

infixl 3 _+_
postulate
  β„• : Ty
  𝟘 πŸ™ 𝟚 πŸ› 𝟞 : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ β„•
  _+_ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ β„• β†’ Ξ“ ⁏ Ξ” ⊒ β„• β†’ Ξ“ ⁏ Ξ” ⊒ β„•

-- Let’s say we have a simple expression referencing a free variable.

e₁ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ , β„• ⁏ Ξ” ⊒ β„•
e₁ = πŸ™ + 𝟚 + vβ‚€

-- We can partially normalise the expression without having to substitute the
-- variable away.

ne₁ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ , β„• ⁏ Ξ” ⊒ β„•
ne₁ = πŸ› + vβ‚€

-- In ICML, we can quote expressions with free variables.  Therefore, if we can
-- check quoted expressions for Ξ±-equivalence, we can distinguish between the
-- original and the partially-normalised version of the expression.

qe₁ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… , β„• ] β„•
qe₁ = box (πŸ™ + 𝟚 + vβ‚€)

qne₁ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… , β„• ] β„•
qne₁ = box (πŸ› + vβ‚€)

-- We can also consider the free variable as a reference to a previously
-- introduced definition, by replacing it with a free meta-variable.

eβ‚‚ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” , [ βˆ… ] β„• ⊒ β„•
eβ‚‚ = πŸ™ + 𝟚 + mvβ‚€ βˆ™

neβ‚‚ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” , [ βˆ… ] β„• ⊒ β„•
neβ‚‚ = πŸ› + mvβ‚€ βˆ™

-- TODO: Unclear whether free meta-variables should or should not be listed in
-- the type of quoted expressions.

qeβ‚‚ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” , [ βˆ… ] β„• ⊒ [ βˆ… ] β„•
qeβ‚‚ = box (πŸ™ + 𝟚 + mvβ‚€ βˆ™)

qneβ‚‚ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” , [ βˆ… ] β„• ⊒ [ βˆ… ] β„•
qneβ‚‚ = box (πŸ› + mvβ‚€ βˆ™)

-- Let’s say we have previously introduced a definition of 3, and we want to
-- reference it in our expression in a manner similar to let-binding, that is:
--   let three = 3 in 1 + 2 + three

e₃ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ β„•
e₃ = unbox {Ξ¨ = βˆ…} (box πŸ›) (πŸ™ + 𝟚 + mvβ‚€ βˆ™)

ne₃ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ β„•
ne₃ = unbox {Ξ¨ = βˆ…} (box πŸ›) (πŸ› + mvβ‚€ βˆ™)

qe₃ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… ] β„•
qe₃ = unbox {Ξ¨ = βˆ…} (box πŸ›) (box (πŸ™ + 𝟚 + mvβ‚€ βˆ™))

qne₃ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… ] β„•
qne₃ = unbox {Ξ¨ = βˆ…} (box πŸ›) (box (πŸ› + mvβ‚€ βˆ™))

-- Now, we can achieve the expected result of splicing by performing one step
-- of reduction, or meta-variable substitution.

qeβ‚„ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… ] β„•
qeβ‚„ = box (πŸ™ + 𝟚 + πŸ›)

qneβ‚„ : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… ] β„•
qneβ‚„ = box (πŸ› + πŸ›)

-- Both of the above quoted expressions are nevertheless different from what we
-- would get by normalising before quoting (box-val).

qeβ‚… : βˆ€ {Ξ“ Ξ”} β†’ Ξ“ ⁏ Ξ” ⊒ [ βˆ… ] β„•
qeβ‚… = box 𝟞