| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some unit types |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Unit.NonEta where |
| 10 |
|
| 11 |
open import Level using (_⊔_; Level) |
| 12 |
|
| 13 |
------------------------------------------------------------------------ |
| 14 |
-- A unit type defined as a data-type |
| 15 |
|
| 16 |
-- The ⊤ type (see Data.Unit) comes with η-equality, which is often |
| 17 |
-- nice to have, but sometimes it is convenient to be able to stop |
| 18 |
-- unfolding (see "Hidden types" below). |
| 19 |
|
| 20 |
data Unit : Set where |
| 21 |
unit : Unit |
| 22 |
|
| 23 |
------------------------------------------------------------------------ |
| 24 |
-- Hidden types |
| 25 |
|
| 26 |
-- "Hidden" values. |
| 27 |
|
| 28 |
Hidden : ∀ {a} → Set a → Set a |
| 29 |
Hidden A = Unit → A |
| 30 |
|
| 31 |
-- The hide function can be used to hide function applications. Note |
| 32 |
-- that the type-checker doesn't see that "hide f x" contains the |
| 33 |
-- application "f x". |
| 34 |
|
| 35 |
hide : ∀ {a b} {A : Set a} {B : A → Set b} → |
| 36 |
((x : A) → B x) → ((x : A) → Hidden (B x)) |
| 37 |
hide f x unit = f x |
| 38 |
|
| 39 |
-- Reveals a hidden value. |
| 40 |
|
| 41 |
reveal : ∀ {a} {A : Set a} → Hidden A → A |
| 42 |
reveal f = f unit |