.. :: {-# OPTIONS --allow-unsolved-metas #-} module language.function-types where open import language.built-ins data Vec (A : Type) : Nat → Type where nil : {n : Nat} → Vec A n cons : {n : Nat} (a : A) (as : Vec A n) → Vec A (suc n) _is-the-same-as_ = _≡_ .. _function-types: ************** Function Types ************** Function types are written ``(x : A) → B``, or in the case of non-dependent functions simply ``A → B``. For instance, the type of the addition function for natural numbers is: .. :: example-hidden₁ : Type example-hidden₁ = :: Nat → Nat → Nat and the type of the addition function for vectors is: .. :: example-hidden₂ : Type₁ example-hidden₂ = :: (A : Type) → (n : Nat) → (u : Vec A n) → (v : Vec A n) → Vec A n where ``Type`` is the type of small types and ``Vec A n`` is the type of vectors with ``n`` elements of type ``A``. Arrows between consecutive hypotheses of the form ``(x : A)`` may also be omitted, and ``(x : A) (y : A)`` may be shortened to ``(x y : A)`` (see also :ref:`telescopes`): .. :: example-hidden₃ : Type₁ example-hidden₃ = :: (A : Type) (n : Nat)(u v : Vec A n) → Vec A n Functions are constructed by :ref:`lambda expressions ` or :ref:`function-definitions`. The application of a function ``f : (x : A) → B`` to an argument ``a : A`` is written ``f a`` and the type of this is ``B[x := a]``. .. _notational-conventions: Notational conventions ---------------------- Function types: .. :: module hidden₁ (A B C : Type) where :: prop₁ : ((x : A) (y : B) → C) is-the-same-as ((x : A) → (y : B) → C) prop₂ : ((x y : A) → C) is-the-same-as ((x : A)(y : A) → C) prop₃ : (forall (x : A) → C) is-the-same-as ((x : A) → C) prop₄ : (forall x → C) is-the-same-as ((x : _) → C) prop₅ : (forall x y → C) is-the-same-as (forall x → forall y → C) .. :: prop₁ = refl prop₂ = refl prop₃ = refl prop₄ = refl prop₅ = refl You can also use the Unicode symbol ``∀`` (type “\\all” in the Emacs Agda mode) instead of ``forall``. Functional abstraction: .. :: prop-hidden₁ : (A : Type) (e : A) → :: (\x y → e) is-the-same-as (\x → (\y → e)) .. :: prop-hidden₁ _ _ = refl Functional application: .. :: prop-hidden₅ : (A B C : Type) (f : A → B → C) (a : A) (b : B) → :: (f a b) is-the-same-as ((f a) b) .. :: prop-hidden₅ _ _ _ _ _ _ = refl