Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstracting away from optics #51

Open
neutropolis opened this issue Feb 23, 2018 · 0 comments
Open

Abstracting away from optics #51

neutropolis opened this issue Feb 23, 2018 · 0 comments

Comments

@neutropolis
Copy link
Member

Hiding optic idioms in favor of more standard names, such as attribute, association, etc. This coq snippet is just a proof of concept.

Record one_to_one (p : Type -> Type) `{Monad p}
                  (record : forall (q : Type -> Type), Monad q -> Type) :=
{ q : Type -> Type
; A : Type
; M : Monad q
; MS : MonadState A q
; ev : record q _
; hom : lensAlgHom p q A
}.
Arguments hom [p _ record].
Arguments ev [p _ record].

Definition attribute := lensAlg'.

Notation "a ▷ f " := (f a) (at level 40, left associativity).

Record Address (p : Type -> Type) `{Monad p} := mkAddress
{ _zip  : attribute p nat
; _city : attribute p string
}.
Arguments _zip [p _].
Arguments _city [p _].

Record Person (p : Type -> Type) `{Monad p} := mkPerson
{ _name    : attribute p string
; _address : one_to_one p Address
}.
Arguments _name [p _].
Arguments _address [p _].

Definition address {p} `{Monad p} (data : Person p) :=
  hom (_address data).

Definition zip {p} `{Monad p} {data : Person p} :=
  _zip (ev (_address data)).

Definition modifyPersonZip {p} `{Monad p}
                           (f : nat -> nat)
                           (data : Person p) : p unit :=
  (data ▷ address • zip) ~ f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant