continuation-passing Questions
2
Solved
Here is some code deciding whether a list is a palindrome in n+1 comparisons, in "direct style"
pal_d1 :: Eq a => [a] -> Bool
pal_d1 l = let (r,_) = walk l l in r
where walk l [] =...
Methaemoglobin asked 12/3, 2021 at 15:12
2
Solved
I have little experience with algebraic data types, because I work in a language without native support. Usually one can use continuation passing style to get a remotely similar experience, but the...
Buckthorn asked 18/1, 2021 at 10:9
1
Consider this Vect type:
{-# LANGUAGE GADTs, DataKinds, KindSignatures, RankNTypes #-}
import Data.Kind (Type)
data Nat = Zero | Succ Nat
data Vect :: Nat -> Type -> Type where
Nil :: Ve...
Antifebrile asked 11/11, 2019 at 13:49
3
Solved
Here is a naive implementation of a right fold:
const foldr = f => acc => ([x, ...xs]) =>
x === undefined
? acc
: f(x) (foldkr(f) (acc) (xs));
This is non-tail recursion and hence w...
Slang asked 30/8, 2019 at 21:24
4
Solved
Note 1 : Here CPS stands for "continuation passing style"
I would be very interested in understanding how to hook into C# async machinery.
Basically as I understand C# async/await feature, the com...
Sheath asked 16/5, 2019 at 14:55
5
Solved
I'm reading through Some Tricks for List Manipulation, and it contains the following:
zipRev xs ys = foldr f id xs snd (ys,[])
where
f x k c = k (\((y:ys),r) -> c (ys,(x,y):r))
What we ...
Cryptocrystalline asked 14/5, 2019 at 1:59
1
Solved
Can you implement CPS using computation expressions in F#?
Brian McNamara's blog gives this solution:
type ContinuationBuilder() =
member this.Return(x) = (fun k -> k x)
member this.Return...
Wept asked 8/4, 2019 at 19:37
2
Solved
I am coming from a OOP, non-functional background, so I am having trouble fully visualizing several online examples regarding continuation passing. Also, functional languages like Scheme don't have...
Temporize asked 27/7, 2016 at 11:29
3
Solved
Here is my Task implementation (i.e. a sort of Promise but complying with the monad laws and cancelable). It works rock solid:
const Task = k =>
({runTask: (res, rej) => k(res, rej)});...
Impracticable asked 16/3, 2019 at 17:5
2
Solved
I've been learning about continuation passing style, particularly the asynchronous version as implemented in javascript, where a function takes another function as a final argument and creates an a...
Taenia asked 16/4, 2012 at 12:12
2
I am having trouble understanding the use of collector functions in Scheme. I am using the book "The Little Schemer" (by Daniel P. Friedman and Matthias Felleisen). A comprehensive example with som...
Radiate asked 26/11, 2016 at 13:58
1
In my previous Quesion:
Extracting data from a function chain without arrays
@Aadit M Shah gave me astonishing solution as follows:
https://mcmap.net/q/1782035/-extracting-data-from-a-function-c...
Calgary asked 19/7, 2018 at 16:33
1
Solved
Summary of my objective: Figure out how to use continuation-passing style to avoid a stack overflow when using an algorithm I believe cannot be made tail-recursive. Alternatively, find a way to mak...
Ungainly asked 29/3, 2018 at 21:32
2
Solved
I am currently experimenting with the continuation monad. Cont is actually useful in Javascript, because it abstracts from the callback pattern.
When we deal with monadic recursion, there is alway...
Insulator asked 24/2, 2018 at 20:57
4
I'm having difficulty understanding what's going on with The Little Schemer's evens-only*&co example on page 145.
Here's the code:
(define evens-only*&co
(lambda (l col)
(cond
((null? ...
Mckay asked 21/5, 2012 at 20:51
7
Solved
The code in question is this:
(define multirember&co
(lambda (a lat col)
(cond
((null? lat)
(col (quote ()) (quote ())))
((eq? (car lat) a)
(multirember&co a
(cdr lat)
(lambda (new...
Unutterable asked 10/8, 2011 at 0:29
1
We can define the continuation monad transformer as
data Cont r m a = Cont {run :: (a -> m r) -> m r}
We can give Cont r m an Alternative instance if m is a member of Alternative via
empt...
Kaleb asked 28/11, 2017 at 5:33
3
Solved
Can someone clarify the need for acc "" when terminating a continuation-based tail-recursive function like in the following example:
let rec repeat_cont i s acc =
if i = 0 then acc ""
else repeat...
Scrope asked 21/5, 2017 at 11:30
4
Solved
The fix-point combinators are very useful tools to introduce recursion.
The Continuation-Passing style is a style of lambda calculus where functions never return. Instead you pass the rest of your...
Seneschal asked 10/3, 2016 at 13:45
2
Solved
I have a function that I want to write in tail recursive form. The function calculates the number of ways to get the sum of k by rolling an s sided die n times. I have seen the mathematical solutio...
Angelika asked 11/1, 2017 at 7:39
3
Solved
(later visitors: two answers to this question both give excellent insight, if you are interested you should probably read them both, I could only except one as a limitation of SO)
From all discuss...
Chantey asked 17/12, 2016 at 20:27
2
Chapter 9 of the book Expert F# 3.0 shows how to use continuation-passing style to avoid stack overflows when traversing binary trees. I have written tree traversal code that is almost identical to...
Swore asked 8/11, 2016 at 0:38
3
Solved
I've been browsing all over the web in search of enlightenment about continuations, and it's mind boggling how the simplest of explanations can so utterly confound a JavaScript programmer like myse...
Inexertion asked 24/12, 2012 at 9:12
2
Solved
After reading The Seasoned Schemer I felt I understood call/cc properly. But, after seeing some WOW tricks with call/cc I found I was wrong.
(define cc 0)
(define (f)
(call/cc (lambda (k)
(set! ...
Grammatical asked 12/6, 2014 at 11:46
3
Solved
Is there a way to chain functions like withCString? By that I mean any
function that looks something like f :: Foo -> (CFoo -> IO a) -> IO a.
For example, lets say there is a function cFu...
Routine asked 22/5, 2016 at 21:46
1 Next >
© 2022 - 2024 — McMap. All rights reserved.