| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Strict combinators (i.e. that use call-by-value) |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- The contents of this module is also accessible via the `Function` |
| 8 |
-- module. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
module Function.Strict where |
| 13 |
|
| 14 |
open import Agda.Builtin.Equality using (_≡_) |
| 15 |
open import Function.Base using (flip) |
| 16 |
open import Level using (Level) |
| 17 |
|
| 18 |
private |
| 19 |
variable |
| 20 |
a b : Level |
| 21 |
A B : Set a |
| 22 |
|
| 23 |
infixl 0 _!|>_ _!|>′_ |
| 24 |
infixr -1 _$!_ _$!′_ |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Dependent combinators |
| 28 |
|
| 29 |
-- These are functions whose output has a type that depends on the |
| 30 |
-- value of the input to the function. |
| 31 |
|
| 32 |
open import Agda.Builtin.Strict public |
| 33 |
renaming |
| 34 |
( primForce to force |
| 35 |
; primForceLemma to force-≡ |
| 36 |
) |
| 37 |
|
| 38 |
-- Application |
| 39 |
_$!_ : ∀ {A : Set a} {B : A → Set b} → |
| 40 |
((x : A) → B x) → ((x : A) → B x) |
| 41 |
f $! x = force x f |
| 42 |
|
| 43 |
-- Flipped application |
| 44 |
_!|>_ : ∀ {A : Set a} {B : A → Set b} → |
| 45 |
(a : A) → (∀ a → B a) → B a |
| 46 |
_!|>_ = flip _$!_ |
| 47 |
|
| 48 |
------------------------------------------------------------------------ |
| 49 |
-- Non-dependent combinators |
| 50 |
|
| 51 |
-- Any of the above operations for dependent functions will also work |
| 52 |
-- for non-dependent functions but sometimes Agda has difficulty |
| 53 |
-- inferring the non-dependency. Primed (′ = \prime) versions of the |
| 54 |
-- operations are therefore provided below that sometimes have better |
| 55 |
-- inference properties. |
| 56 |
|
| 57 |
seq : A → B → B |
| 58 |
seq a b = force a (λ _ → b) |
| 59 |
|
| 60 |
seq-≡ : (a : A) (b : B) → seq a b ≡ b |
| 61 |
seq-≡ a b = force-≡ a (λ _ → b) |
| 62 |
|
| 63 |
force′ : A → (A → B) → B |
| 64 |
force′ = force |
| 65 |
|
| 66 |
force′-≡ : (a : A) (f : A → B) → force′ a f ≡ f a |
| 67 |
force′-≡ = force-≡ |
| 68 |
|
| 69 |
-- Application |
| 70 |
_$!′_ : (A → B) → (A → B) |
| 71 |
_$!′_ = _$!_ |
| 72 |
|
| 73 |
-- Flipped application |
| 74 |
_!|>′_ : A → (A → B) → B |
| 75 |
_!|>′_ = _!|>_ |