Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created October 16, 2019 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisdk/be6d11235c675caf6757c1c94b71c8a1 to your computer and use it in GitHub Desktop.
Save oisdk/be6d11235c675caf6757c1c94b71c8a1 to your computer and use it in GitHub Desktop.
{-# OPTIONS --safe --without-K #-}
module Bits where
infixr 4 _×_ _,_
record _×_ (A : Set) (B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_
data _+_ (A : Set) (B : Set) : Set where
inl : A → A + B
inr : B → A + B
record Lens (S : Set) (T : Set) (A : Set) (B : Set) : Set₁ where
field
X : Set
Y : X → Set
viewˡ : X → S
viewʳ : X → A
updateˡ : (x : X) → T → Y x
updateʳ : (x : X) → B → Y x
open Lens
compose : ∀ {S T A B P Q} → Lens S T A B → Lens A B P Q → Lens S T P Q
compose xs ys .X = xs .X × ys .X
compose xs ys .Y (x , y) = xs .Y x + ys .Y y
compose xs ys .viewˡ (x , y) = xs .viewˡ x
compose xs ys .viewʳ (x , y) = ys .viewʳ y
compose xs ys .updateˡ (x , y) t = inl (xs .updateˡ x t)
compose xs ys .updateʳ (x , y) t = inr (ys .updateʳ y t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment