Scheme.Semantic Functions
{-# OPTIONS --allow-unsolved-metas #-} module Scheme.Semantic-Functions where open import Scheme.Domain-Notation open import Scheme.Abstract-Syntax open import Scheme.Domain-Equations open import Scheme.Auxiliary-Functions -- 7.2.3. Semantic functions postulate π¦β¦_β§ : Con β π β°β¦_β§ : Exp β π β π β π β°ββ¦_β§ : Exp ββ² β π β π β π πββ¦_β§ : Com ββ² β π β π β π -- Definition of π¦ deliberately omitted. β°β¦ con K β§ = Ξ» Ο ΞΊ β send (π¦β¦ K β§) ΞΊ β°β¦ ide I β§ = Ξ» Ο ΞΊ β hold (lookup Ο I) (single (Ξ» Ο΅ β (misc-undefined β―) (β» Ο΅) βΆ wrong "undefined variable" , send Ο΅ ΞΊ)) -- Non-compositional: -- β°β¦ β¦ Eβ β£ Eβ β¦ β§ = -- Ξ» Ο ΞΊ β β°ββ¦ permute (β¨ Eβ β© Β§ Eβ ) β§ -- Ο -- (Ξ» Ο΅β β ((Ξ» Ο΅β β applicate (Ο΅β β 1) (Ο΅β β 1) ΞΊ) -- (unpermute Ο΅β))) β°β¦ β¦ Eβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β°β¦ Eβ β§ Ο (single (Ξ» Ο΅β β β°ββ¦ Eβ β§ Ο (β Ξ» Ο΅β β applicate Ο΅β Ο΅β ΞΊ))) β°β¦ β¦ lambdaβ£β¦ Iβ β¦ Ξβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β Ξ» Ο β (new Ο βπ) βΆ β» (send (β ( (new Ο |π) , (Ξ» Ο΅β ΞΊβ² β (# Ο΅β ==β₯ #β² Iβ) βΆ tievals (Ξ» Ξ±β β (Ξ» Οβ² β πββ¦ Ξβ β§ Οβ² (β°β¦ Eβ β§ Οβ² ΞΊβ²)) (extends Ο Iβ Ξ±β)) Ο΅β , wrong "wrong number of arguments" ) ) π -in-π) ΞΊ) (update (new Ο |π) unspecified-in-π Ο) , β» (wrong "out of memory") Ο
\clearpage
β°β¦ β¦ lambdaβ£β¦ Iβ Β· I β¦ Ξβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β Ξ» Ο β (new Ο βπ) βΆ β» (send (β ( (new Ο |π) , (Ξ» Ο΅β ΞΊβ² β (# Ο΅β >=β₯ #β² Iβ) βΆ tievalsrest (Ξ» Ξ±β β (Ξ» Οβ² β πββ¦ Ξβ β§ Οβ² (β°β¦ Eβ β§ Οβ² ΞΊβ²)) (extends Ο (Iβ Β§β² ( 1 , I )) Ξ±β)) Ο΅β (Ξ· (#β² Iβ)) , wrong "too few arguments" ) ) π -in-π) ΞΊ) (update (new Ο |π) unspecified-in-π Ο) , β» (wrong "out of memory") Ο -- Non-compositional: -- β°β¦ β¦ lambda I β£ Ξβ β£ Eβ β¦ β§ = β°β¦ β¦ lambda β¦ Β· I β¦ Ξβ β£ Eβ β¦ β§ β°β¦ β¦ lambda I β£ Ξβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β Ξ» Ο β (new Ο βπ) βΆ β» (send (β ( (new Ο |π) , (Ξ» Ο΅β ΞΊβ² β tievalsrest (Ξ» Ξ±β β (Ξ» Οβ² β πββ¦ Ξβ β§ Οβ² (β°β¦ Eβ β§ Οβ² ΞΊβ²)) (extends Ο (1 , I) Ξ±β)) Ο΅β (Ξ· 0)) ) π -in-π) ΞΊ) (update (new Ο |π) unspecified-in-π Ο) , β» (wrong "out of memory") Ο β°β¦ β¦ if Eβ β£ Eβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β°β¦ Eβ β§ Ο (single (Ξ» Ο΅ β truish Ο΅ βΆ β°β¦ Eβ β§ Ο ΞΊ , β°β¦ Eβ β§ Ο ΞΊ)) β°β¦ β¦ if Eβ β£ Eβ β¦ β§ = Ξ» Ο ΞΊ β β°β¦ Eβ β§ Ο (single (Ξ» Ο΅ β truish Ο΅ βΆ β°β¦ Eβ β§ Ο ΞΊ , send unspecified-in-π ΞΊ)) -- Here and elsewhere, any expressed value other than `undefined` -- may be used in place of `unspecified`.
\clearpage
β°β¦ β¦ set! I β£ E β¦ β§ = Ξ» Ο ΞΊ β β°β¦ E β§ Ο (single (Ξ» Ο΅ β assign (lookup Ο I) Ο΅ (send unspecified-in-π ΞΊ))) -- β°ββ¦_β§ : Exp ββ² β π β π β π β°ββ¦ 0 , _ β§ = Ξ» Ο ΞΊ β β» ΞΊ β¨β© -- Cannot split on argument of non-datatype Exp ^ suc n: -- β°ββ¦ suc n , E , Es β§ = Ξ» Ο ΞΊ β -- β°β¦ E β§ Ο (single (Ξ» Ο΅β β -- β°ββ¦ n , Es β§ Ο (β Ξ» Ο΅β β -- β» ΞΊ (β¨ Ο΅β β© Β§ Ο΅β)))) β°ββ¦ 1 , E β§ = Ξ» Ο ΞΊ β β°β¦ E β§ Ο (single (Ξ» Ο΅ β β» ΞΊ β¨ Ο΅ β© )) β°ββ¦ suc (suc n) , E , Es β§ = Ξ» Ο ΞΊ β β°β¦ E β§ Ο (single (Ξ» Ο΅β β β°ββ¦ suc n , Es β§ Ο (β Ξ» Ο΅β β β» ΞΊ (β¨ Ο΅β β© Β§ Ο΅β)))) -- πββ¦_β§ : Com ββ² β π β π β π πββ¦ 0 , _ β§ = Ξ» Ο ΞΈ β ΞΈ πββ¦ 1 , Ξ β§ = Ξ» Ο ΞΈ β β°β¦ Ξ β§ Ο (β Ξ» Ο΅β β ΞΈ) πββ¦ suc (suc n) , Ξ , Ξs β§ = Ξ» Ο ΞΈ β β°β¦ Ξ β§ Ο (β Ξ» Ο΅β β πββ¦ suc n , Ξs β§ Ο ΞΈ)