Comments (8)
Generic n-ary lift
for applicatives following a discussion with @Zambonifofex
open import Category.Applicative using (RawApplicative) hiding (module RawApplicative)
module _ (Test : ∀ {ℓ} → Set ℓ → Set ℓ)
(raw-applicative : ∀ ℓ → RawApplicative (Test {ℓ})) where
open import Data.Unit
open import Level using (_⊔_; Lift)
open import Data.Nat.Base
open import Data.Product
open import Data.Product.Nary.NonDependent
open import Function
open import Function.Nary.NonDependent
module App {ℓ} = Category.Applicative.RawApplicative (raw-applicative ℓ)
Productκ : ∀ n {l} (as : Sets n (lreplicate n l)) → Set l
Productκ zero as = Lift _ ⊤
Productκ (suc n) (a , as) = a × Productκ n as
toProductκ : ∀ n {l} {as : Sets n (lreplicate n l)} → Product⊤ n as → Productκ n as
toProductκ zero _ = _
toProductκ (suc n) (v , vs) = v , toProductκ n vs
fromProductκ : ∀ n {l} {as : Sets n (lreplicate n l)} → Productκ n as → Product⊤ n as
fromProductκ zero _ = _
fromProductκ (suc n) (v , vs) = v , fromProductκ n vs
curryκₙ : ∀ n {l} {as : Sets n (lreplicate n l)} {r} {b : Set r} →
(Productκ n as → b) → as ⇉ b
curryκₙ n f = curry⊤ₙ n (f ∘ toProductκ n)
uncurryκₙ : ∀ n {l} {as : Sets n (lreplicate n l)} {r} {b : Set r} →
as ⇉ b → (Productκ n as → b)
uncurryκₙ n f = uncurry⊤ₙ n f ∘ fromProductκ n
sequenceA : ∀ n {l} {as : Sets n (lreplicate n l)} →
Productκ n (Test <$> as) → Test (Productκ n as)
sequenceA zero p = App.pure p
sequenceA (suc n) (ta , p) = _,_ App.<$> ta App.⊛ sequenceA n p
lift : ∀ n {l} {R : Set l} {As : Sets n (lreplicate n l)} →
As ⇉ R → (Test <$> As) ⇉ Test R
lift n f = curryκₙ n (λ ps → uncurryκₙ n f App.<$> sequenceA n ps)
from agda-stdlib.
How about
open import Level using (Level)
open import Function
open import Function.Nary.NonDependent
open import Data.Nat
open import Data.Product using (_×_; _,_; proj₁; proj₂) renaming (curry to curry₂; uncurry to uncurry₂)
open import Data.List using (List; []; _∷_; map) renaming (zipWith to zipWith₂)
variable
l : Level
R : Set l
zipWith : ∀ n {ls} {as : Sets n ls} →
Arrows n as R → Arrows n (List <$> as) (List R)
zipWith zero f = []
zipWith (suc zero) f = map f
zipWith (suc (suc n)) f xs₀ xs₁ = zipWith (suc n) id (zipWith₂ f xs₀ xs₁)
or alternatively
zipWith : ∀ n {ls} {as : Sets n ls} →
Arrows n as R → Arrows n (List <$> as) (List R)
zipWith zero f = []
zipWith (suc zero) f = map f
zipWith (suc (suc n)) f xs₀ xs₁ = zipWith (suc n) (uncurry₂ f) (zipWith₂ _,_ xs₀ xs₁)
from agda-stdlib.
So off the top of my head I'm struggling to come up with a generalised zipWith-n
function which is both sufficiently general and easy to reason about. Do you have such an implementation?
I don't think zip3with
is common or useful enough to warrant being included in the standard library.
from agda-stdlib.
Closing as I'm afraid I can't come up with a suitable zipWith-n
function.
from agda-stdlib.
I think this ought to be doable using the code in #608
Edit: yep. uncurried version (_<$>_
is map over Sets
using a level polymorphic endofunctor on Set l
):
zw-aux : ∀ n {ls} {as : Sets n ls} →
(Product n as → R) →
(Product n (List <$> as) → List R)
zw-aux 0 f as = []
zw-aux 1 f (as , _) = map (f ∘ (_, tt)) as
zw-aux (suc n) f (as , ass) = zipWith _$_ fs as
where fs = zw-aux n (flip (curry f)) ass
from agda-stdlib.
I like the second one better. I am puzzled because I tried my best and I really
could not see how to implement it.
from agda-stdlib.
Going to remove the v1.1
milestone for this as I don't think it's urgent.
from agda-stdlib.
Fixed by 58462cf. Congrats to @gallais for fixing by far the oldest issue in the library!
from agda-stdlib.
Related Issues (20)
- A distribution tarball beyond github's autogenerated one?
- Add certain proofs for ``_∤_`` HOT 7
- Refactor to support multiple definitions of `Data.List.Relation.Binary.Permutation` HOT 10
- Add `AlmostRightCancellative` proof to ` IsCancellativeCommutativeSemiring` HOT 3
- Can we unify Relation.Binary.Morphism.Definitions and Function.Definitions? HOT 2
- Parsing problems with the `PermutationReasoning` combinators in `Data.List.Relation.Binary.Permutation.Propositional` HOT 15
- move `decToMaybe` from `Data.Maybe.Base` to `Data.Maybe` HOT 8
- move `_≗_` from `Relation.Binary.PropositionalEquality` to `*.Core` HOT 3
- What should our explicit import policy be? HOT 4
- Consistently add the equality after `resp` in proof names. HOT 1
- Deprecate existing definition of `⊥-elim` in favour of its irrelevant version `⊥-elim-irr`
- Add `Algebra.Action.*` HOT 9
- Add `Algebra.Construct.WreathProduct` and/or `Algebra.Construct.SemiDirectProduct` HOT 7
- Organizing 3.0
- ``_=ₛ_`` and ``⊆ + reverse`` for lib-2.0 HOT 4
- List of wrinkles in `Data.List.Properties` HOT 7
- List of sub-optimal definitions in `Data.List.Base` HOT 25
- Add the `Setoid`al structure of a (free) `Monoid` on `List` HOT 1
- lib2.0 : `ℕᵇ `(binary) can be pure unlike `ℕ`. HOT 8
- To let or not to let HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agda-stdlib.