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)
- Rename `WeaklyDecidable`? HOT 4
- Add `Algebra.Properties.IdempotentCommutativeMonoid`
- Naming of new functions `tail∘inits` and `tail∘tails` HOT 5
- comments on lib-2.1 candidate 1 HOT 9
- Unify general algebraic definitions of Divisibility and Primarity with those in Nat and Integer HOT 7
- Style for lower/upper case for initial letter in denotations HOT 7
- Restore missing proofs from `Algebra.Operations.CommutativeMonoid`
- Proofs in `Data.Vec.Properties` take general properties as inputs HOT 23
- Unsolved metas in `Data.List.Properties` cf. discussion on #2415, #2359, #2365 HOT 3
- [DRY] Refactor the various definitions of 'pointwise' equality on functions/`Function`s/pointwise `Algebra`s HOT 2
- Data.Nat.Properties.≤-total should be implemented with _<ᵇ_ HOT 14
- Data.List.upTo/applyUpTo can be made faster HOT 5
- Linear-time implementation of `Data.Nat.Properties.≤′⇒≤`? HOT 3
- Regression in the documentation of installation HOT 1
- Refactor ` Data.Nat.GeneralisedArithmetic` HOT 2
- Derived operators in the theory of `Relation.Binary.Structures.IsTotalOrder` HOT 5
- Deploy doc rendering for v2.1 HOT 2
- Add `Algebra.Definitions.RawGroup` and `Algebra.Properties.Group.*` HOT 5
- Get rid of inconsistent `homo` name in algebra hierarchy? HOT 5
- Release v2.1.1 HOT 22
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.