Is it possible to nest this kind of "continuation" (a -> b -> r)

Hello, I have this nest ∷ [(a → r) → r] → ([a] → r) → r nest xs = runCont (Prelude.mapM cont xs) but now I need this nest2 ∷ [(a → b → r) → r] → ([a] → [b] → r) → r nest2 xs = ... and this nest3 :: ... Do you think that there is a generic way to write all these nestX methodes. thanks for your help Frédéric

On Fri, Apr 19, 2024 at 06:29:23PM +0200, PICCA Frederic-Emmanuel wrote:
nest ∷ [(a → r) → r] → ([a] → r) → r nest xs = runCont (Prelude.mapM cont xs)
nest2 ∷ [(a → b → r) → r] → ([a] → [b] → r) → r nest2 xs = ...
nest3 :: ...
Do you think that there is a generic way to write all these nestX methodes.
I doubt it. There's not even a generic way of writing out the non-CPSed versions nest2 :: [(a, b)] -> ([a], [b]) nest3 :: [(a, b, c)] -> ([a], [b], [c]) Instead we just have individually-named unzip functions: https://www.stackage.org/haddock/lts-22.17/base-4.18.2.0/Prelude.html#v:unzi... https://www.stackage.org/haddock/lts-22.17/base-4.18.2.0/Prelude.html#v:unzi... Tom

Well, if we used type indexed lists (aka just "dynamic tuples") it should be possible, right? I.e. hunzip :: [HList xs] -> HList (ToList xs) type family ToList xs where ToList '[x] = [x] ToList (x ': xs) = [x] ': ToList xs On 4/19/24 19:59, Tom Ellis wrote:
On Fri, Apr 19, 2024 at 06:29:23PM +0200, PICCA Frederic-Emmanuel wrote:
nest ∷ [(a → r) → r] → ([a] → r) → r nest xs = runCont (Prelude.mapM cont xs)
nest2 ∷ [(a → b → r) → r] → ([a] → [b] → r) → r nest2 xs = ...
nest3 :: ...
Do you think that there is a generic way to write all these nestX methodes. I doubt it. There's not even a generic way of writing out the non-CPSed versions
nest2 :: [(a, b)] -> ([a], [b]) nest3 :: [(a, b, c)] -> ([a], [b], [c])
Instead we just have individually-named unzip functions:
https://www.stackage.org/haddock/lts-22.17/base-4.18.2.0/Prelude.html#v:unzi... https://www.stackage.org/haddock/lts-22.17/base-4.18.2.0/Prelude.html#v:unzi...
Tom _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

I would think in terms of: nest :: Applicative f => [f a] -> f [a] nest = sequenceA nest2 :: Applicative f => [f (a,b)] -> f ([a],[b]) nest2 = fmap unzip . sequenceA nest3 :: Applicative f => [f (a,b,c)] -> f ([a],[b],[c]) nest3 = fmap unzip3 . sequenceA Then put f = Cont r On 2024-04-19 12:29, PICCA Frederic-Emmanuel wrote:
Hello, I have this
nest ∷ [(a → r) → r] → ([a] → r) → r nest xs = runCont (Prelude.mapM cont xs)
but now I need this
nest2 ∷ [(a → b → r) → r] → ([a] → [b] → r) → r nest2 xs = ...
and this
nest3 :: ...
Do you think that there is a generic way to write all these nestX methodes.
thanks for your help
Frédéric _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (4)
-
Albert Y. C. Lai
-
Georgi Lyubenov
-
PICCA Frederic-Emmanuel
-
Tom Ellis