Skip to content

Commit

Permalink
Singleton list notation.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed May 7, 2018
1 parent ae3264b commit f8f1ac3
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/Examples/Types.lagda.tex
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
\begin{code}
module Examples.Types where

open import Level using (_⊔_)

open import Data.Unit using (⊤ ; tt)
open import Data.Bool using (Bool ; false ; true)
open import Data.Nat using (ℕ ; zero ; suc ; _+_)
open import Data.Vec using (Vec ; [] ; _∷_)
open import Data.List using (List ; [] ; _∷_)
open import Data.List.All using (All ; [] ; _∷_)
open import Data.String using (String)
open import ActorMonad
open import Membership using (_⊆_ ; _∷_ ; [] ; S ; Z)
open import Membership using (_∈_; _⊆_ ; _∷_ ; [] ; S ; Z)

record Singleton {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
field
[_] : A → B
open Singleton {{...}}

instance
singletonList : ∀{a}{A : Set a} → Singleton A (List A)
singletonList .Singleton.[_] a = a ∷ []

singletonAll : ∀{a p} {A : Set a} {P : A → Set p} {x : A} → Singleton (P x) (All P (x ∷ []))
singletonAll .Singleton.[_] p = p ∷ []

singletonMem : ∀{a} {A : Set a} {x : A} {ys : List A} → Singleton (x ∈ ys) ((x ∷ []) ⊆ ys)
singletonMem .Singleton.[_] p = p ∷ []

[_]ˡ : ∀{a}{A : Set a} → A → List A
[ a ]ˡ = a ∷ []

[_]ᵐ : ∀{a} {A : Set a} {x : A} {ys : List A} → (x ∈ ys) → ((x ∷ []) ⊆ ys)
[ p ]ᵐ = p ∷ []
\end{code}

%<*PropositionalEquality>
Expand Down Expand Up @@ -57,24 +80,23 @@
\begin{code}
TestInbox : InboxShape
TestInbox = ( ReferenceType (
(ValueType String ∷ [])
(ValueType Bool ∷ [])
[ ValueType String
[ ValueType Bool
∷ [])
∷ ValueType ℕ
∷ [])
(ValueType Bool ∷ [])
[ ValueType Bool
∷ []
\end{code}
%</ExampleInbox>

%<*Subtyping>
\begin{code}
Boolbox : InboxShape
Boolbox = (ValueType Bool ∷ [])
∷ []
Boolbox = [ [ ValueType Bool ]ˡ ]ˡ

test-subtyping : Boolbox <: TestInbox
test-subtyping = (S Z) ∷ []
test-subtyping = [ S Z ]ᵐ
\end{code}
%</Subtyping>
%<*PartialFunction>
Expand Down

0 comments on commit f8f1ac3

Please sign in to comment.