Questions tagged [cps]

Continuation-passing style. Use tag [continuation-passing].

Continuation-passing style. Use tag .

References

18 questions
172
votes
1 answer

Sneaking lenses and CPS past the value restriction

I'm encoding a form of van Laarhoven lenses in OCaml, but am having difficulty due to the value restriction. The relevant code is as follows: module Optic : sig type (-'s, +'t, +'a, -'b) t val lens : ('s -> 'a) -> ('s -> 'b -> 't) -> ('s, 't,…
J. Abrahamson
  • 72,246
  • 9
  • 135
  • 180
4
votes
1 answer

What does cps do in redux saga?

It's about 5 months that I work with redux-saga, it's a great and strong middleware library. I know almost everything in redux-saga, but I couldn't still understand "cps". Can anyone explain me (with an example) what can be done with "cps"? I really…
Amir Gorji
  • 2,809
  • 1
  • 21
  • 26
3
votes
2 answers

how to converting function to cps recursively

i'd like to define cpsRec as follows but i couldn't. please let me know if you come up with ideas for implementation. import Control.Monad.Trans.Cont (Cont) type family ContRec r x where ContRec r (a -> b) = a -> ContRec r b ContRec r a = Cont…
2
votes
1 answer

How to speed up the trampolined cps version fib function and support mutual recursion in python?

I have try to implement trampoline for a cps version of fibonacci function. But I can't make it fast (add cache) and support mutual_recursion. The implement code: import functools from dataclasses import dataclass from typing import Optional, Any,…
jiamo
  • 1,406
  • 1
  • 17
  • 29
1
vote
2 answers

fibonacci cps implementation

I'm trying to convert different function from tail recursive to cps (continuation passing style). I managed to do a sum and factorial function: Sum function: Tail recursive: let sum n = let rec subSum n acc = match n with |0 -> acc |_…
mxbr236
  • 39
  • 6
1
vote
2 answers

yet another question about python continuations

all trying to work out how continuations work in python. i have the following code to calculate fibonacci using a python cps implementation ( i realize that it is building a stack, but for this question i am hoping this code will be sufficient…
1
vote
1 answer

Jenkins scripted pipleline @NonCPS and StackOverflowError

I have the simple pipeline script: #!groovy @org.jenkinsci.plugins.workflow.libs.Library('Some@lib') import com.cloudbees.groovy.cps.NonCPS node() { echo CheekyEnum.getByName('name1').getName() } enum CheekyEnum { ENUM_1('name1',…
RedMurloc
  • 115
  • 1
  • 11
1
vote
0 answers

Transforming scheme into CPS to desugar call/cc

context: I'm currently writing a small scheme compiler and took the approach of first transforming into administrative normal form and then into cps (I find this to be the easiest to understand, since there is a clear seperation in what they…
Tim Eichholz
  • 119
  • 1
  • 7
0
votes
0 answers

Javascript to Continuation Passing Style

I am trying to get the hang of CPS and was wondering if anyone could walk me through converting this example function: function recur(n) { if (n == 0) { return 1; } else { return n * recur(n-1); } } I know that the…
0
votes
1 answer

Continuation Passing Style in Haskell with Binary Tree

I'm just learning CPS and I'm trying to pass the following program to this style mirror Void = Void mirror (Node x left right) = Node x (mirror right) (mirror left) From what I understand I have to pass the continuation the base case and in the…
Márquez
  • 91
  • 7
0
votes
1 answer

How do I make a div click without the mouse moving?

I'm trying to make a JavaScript code that injects into cpstest.org and when you click the start button, it automatically starts auto-clicking. I tried to make a script for it, but it just didn't work. The start button has id start but I don't know…
0
votes
2 answers

F# CPS evaluation order

I'm trying to understand the order of evaluation when using Continuation-passing style in F#. Take this function for example. let rec CPSfunc n k c = if k = 0 then c 1 else if k > 0 then CPSfunc n (k-1) (fun res -> c(2*res+k)) When running…
Bassusour
  • 175
  • 6
  • 14
0
votes
1 answer

R - Can't access CPS data using lodown package

The lodown packages works great for me for the most part - was able to download ACS and CES data without issue. But when I try to use it to access CPS data, I get the following output: lodown( "cpsbasic" , output_dir = file.path( path.expand( "~" )…
0
votes
1 answer

Jenkins/groovy CPS issue : artifactoryUpload

I'm getting same issue listed as fixed here : https://issues.jenkins.io/browse/JENKINS-58643 We are using Jenkins 2.190.3.2 stage('upload artefactory') { steps { sh "touch /tmp/blabla" sh "gzip…
FF123
  • 37
  • 4
0
votes
1 answer

How do I execute a function X times per second?

I am writing an auto clicker and want to have the delay as a CPS (clicks per second) so, how would I work out the delay from the CPS value in python? I have tried googling but only found CPS testers, no actual code Here is a snippet of code: def…
Zax71
  • 45
  • 7
1
2