-
Notifications
You must be signed in to change notification settings - Fork 257
Add new module Effect.Functor.Naperian
- Continuation of #2004
#2815
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
Open
gabriellisboaconegero
wants to merge
20
commits into
agda:master
Choose a base branch
from
gabriellisboaconegero:functor_naperian
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1a86ef4
Upload new file Effect.Functor.Naperian to stdlib
Sofia-Insa 0dd5051
Update CHANGELOG.md
Sofia-Insa af6d2dc
Merge branch 'task2-Naperian' of https://github.com/Sofia-Insa/agda-s…
Sofia-Insa eba481c
Update CHANGELOG.md
Sofia-Insa 603483f
updated `CHANGELOG`
jamesmckinna 7dcb115
added note
jamesmckinna d76c8df
Merge branch 'master' into task2-Naperian
jamesmckinna 73bd5bd
hopefully now fixed merge conflict with up-to-date `CHANGELOG`
jamesmckinna e233f0e
restored original details to `CHANGELOG`
jamesmckinna ad30c67
review comments from me
jamesmckinna 775560f
Merge branch 'master' into task2-Naperian
JacquesCarette 6804ecd
Setoid version of Naperian -- needs another pair of eyes.
JacquesCarette a1de89f
whitespace
JacquesCarette 527e4d7
[FIX]: Naming + Propositional Naperian
gabriellisboaconegero 3c478d3
[REFAC]: RawFunctor as part of RawNaperian + james revision
gabriellisboaconegero d697f2c
Merge branch 'master' into functor_naperian
gabriellisboaconegero 0741736
[DOC]: Update CHANGELOG
gabriellisboaconegero 5216bbb
[ADD]: Vec n is Naperian; rawNaperian to rawApplicative
gabriellisboaconegero ffda892
[NAMING]: Correct naming in Vec.Effectful and Naperian
gabriellisboaconegero 6ad71f0
[NAMING]: ETA contract
gabriellisboaconegero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Naperian functor | ||
-- | ||
-- Definitions of Naperian Functors, as named by Hancock and McBride, | ||
-- and subsequently documented by Jeremy Gibbons | ||
-- in the article "APLicative Programming with Naperian Functors" | ||
-- which appeared at ESOP 2017. | ||
-- https://link.springer.com/chapter/10.1007/978-3-662-54434-1_21 | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Effect.Functor.Naperian where | ||
|
||
open import Effect.Functor using (RawFunctor) | ||
open import Level using (Level; suc; _⊔_) | ||
open import Relation.Binary.Bundles using (Setoid) | ||
open import Relation.Binary.PropositionalEquality.Properties as ≡ using (setoid) | ||
open import Function.Base using (_∘_) | ||
|
||
private | ||
variable | ||
a b c ℓ : Level | ||
A : Set a | ||
|
||
-- From the paper: | ||
-- "Functor f is Naperian if there is a type p of ‘positions’ such that fa≃p→a; | ||
-- then p behaves a little like a logarithm of f | ||
-- in particular, if f and g are both Naperian, | ||
-- then Log(f×g)≃Logf+Logg and Log(f.g) ≃ Log f × Log g" | ||
|
||
-- RawNaperian contains just the functions, not the proofs | ||
module _ (F : Set a → Set b) c where | ||
record RawNaperian : Set (suc (a ⊔ c) ⊔ b) where | ||
field | ||
rawFunctor : RawFunctor F | ||
Log : Set c | ||
index : F A → (Log → A) | ||
tabulate : (Log → A) → F A | ||
open RawFunctor rawFunctor public | ||
|
||
-- Full Naperian has the coherence conditions too. | ||
|
||
record Naperian (S : Setoid a ℓ) : Set (suc (a ⊔ c) ⊔ b ⊔ ℓ) where | ||
field | ||
rawNaperian : RawNaperian | ||
open RawNaperian rawNaperian public | ||
open module S = Setoid S | ||
private | ||
FS : Setoid b (c ⊔ ℓ) | ||
FS = record | ||
{ _≈_ = λ (fx fy : F Carrier) → ∀ (l : Log) → index fx l ≈ index fy l | ||
; isEquivalence = record | ||
{ refl = λ _ → refl | ||
; sym = λ eq l → sym (eq l) | ||
; trans = λ i≈j j≈k l → trans (i≈j l) (j≈k l) | ||
} | ||
} | ||
module FS = Setoid FS | ||
field | ||
index-tabulate : (f : Log → Carrier) → ((l : Log) → index (tabulate f) l ≈ f l) | ||
natural-tabulate : (f : Carrier → Carrier) (k : Log → Carrier) → (tabulate (f ∘ k)) FS.≈ (f <$> (tabulate k)) | ||
natural-index : (f : Carrier → Carrier) (as : F Carrier) (l : Log) → (index (f <$> as) l) ≈ f (index as l) | ||
|
||
tabulate-index : (fx : F Carrier) → tabulate (index fx) FS.≈ fx | ||
tabulate-index = index-tabulate ∘ index | ||
|
||
PropositionalNaperian : Set (suc (a ⊔ c) ⊔ b) | ||
PropositionalNaperian = ∀ A → Naperian (≡.setoid A) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Can
natural-tabulate
also be eliminated by defining it in terms ofindex-tabulate
,natural-index
, andtabulate-index
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can without assuming congruence on the setoid. I was trying to do so, but I was stuck and needed to prove the function congruence on the setoid
S
. I could figure out thatIf I assume
≈
congruence, then I could provetabulate-index
.I don't think we can find a proof for
tabulate-index
without congruence, but I am not sure. I base my argument on the fact thattabulate-∘
needscong
to be proved.