| 1 |
(* -*- coding: utf-8 -*- *) |
| 2 |
(************************************************************************) |
| 3 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 4 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 5 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 6 |
(* \VV/ **************************************************************) |
| 7 |
(* // * This file is distributed under the terms of the *) |
| 8 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 9 |
(* * (see LICENSE file for the text of the license) *) |
| 10 |
(************************************************************************) |
| 11 |
(** Standard functions and combinators. |
| 12 |
|
| 13 |
Proofs about them require functional extensionality and can be found |
| 14 |
in [Combinators]. |
| 15 |
|
| 16 |
Author: Matthieu Sozeau |
| 17 |
Institution: LRI, CNRS UMR 8623 - University Paris Sud |
| 18 |
*) |
| 19 |
|
| 20 |
(** The polymorphic identity function is defined in [Datatypes]. *) |
| 21 |
|
| 22 |
Arguments id {A} x. |
| 23 |
|
| 24 |
(** Function composition. *) |
| 25 |
|
| 26 |
Definition compose {A B C} (g : B -> C) (f : A -> B) := |
| 27 |
fun x : A => g (f x). |
| 28 |
|
| 29 |
#[global] |
| 30 |
Hint Unfold compose : core. |
| 31 |
|
| 32 |
Declare Scope program_scope. |
| 33 |
|
| 34 |
Notation " g ∘ f " := (compose g f) |
| 35 |
(at level 40, left associativity) : program_scope. |
| 36 |
|
| 37 |
Local Open Scope program_scope. |
| 38 |
|
| 39 |
(** The non-dependent function space between [A] and [B]. *) |
| 40 |
|
| 41 |
Definition arrow (A B : Type) := A -> B. |
| 42 |
Register arrow as core.arrow. |
| 43 |
|
| 44 |
(** Logical implication. *) |
| 45 |
|
| 46 |
Definition impl (A B : Prop) : Prop := A -> B. |
| 47 |
Register impl as core.impl. |
| 48 |
|
| 49 |
(** The constant function [const a] always returns [a]. *) |
| 50 |
|
| 51 |
Definition const {A B} (a : A) := fun _ : B => a. |
| 52 |
|
| 53 |
(** The [flip] combinator reverses the first two arguments of a function. *) |
| 54 |
|
| 55 |
Definition flip {A B C} (f : A -> B -> C) x y := f y x. |
| 56 |
Register flip as core.flip. |
| 57 |
|
| 58 |
(** Application as a combinator. *) |
| 59 |
|
| 60 |
Definition apply {A B} (f : A -> B) (x : A) := f x. |