Skip to content

Instantly share code, notes, and snippets.

@gallais
Created August 2, 2020 14:52
Show Gist options
  • Save gallais/d23c5b5360c5279bc9d0c071b69855cc to your computer and use it in GitHub Desktop.
Save gallais/d23c5b5360c5279bc9d0c071b69855cc to your computer and use it in GitHub Desktop.
Returning a smaller sized list
open import Agda.Builtin.Size
open import Data.Maybe.Base
data List {n} (T : Set n) (i : Size) : Set n where
[] : List T i
_∷_ : ∀ {j : Size< i} → T → List T j → List T i
data Smaller {n} (T : Size → Set n) (i : Size) : Set n where
[_] : {j : Size< i} → T j → Smaller T i
f : ∀ {n} {T : Set n} {i} → List T i → Maybe (Smaller (List T) i)
f [] = nothing
f (x ∷ xs) = just [ xs ]
g : ∀ {n} {T : Set n} {i} → List T i → Maybe (Smaller (List T) i)
g [] = nothing
g (_ ∷ []) = nothing
g (_ ∷ (_ ∷ xs)) = just [ xs ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment