-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented pure transforming of context function
- Loading branch information
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
shared/src/test/scala/cpstest/TestNonShiftedContextFunction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cpstest | ||
|
||
import scala.util.* | ||
|
||
import cps.{*,given} | ||
import cps.monads.{*, given} | ||
|
||
import org.junit.{Test,Ignore} | ||
|
||
class TestNonShiftedContextFunction { | ||
|
||
case class Context(x:String) | ||
|
||
|
||
|
||
object O { | ||
|
||
def apply[T](c:Context ?=> T): T = c(using Context("O")) | ||
|
||
def p0(x: => Int): Int = x + 1 | ||
def p0_async(x:() => ComputationBound[Int]): Int = | ||
x().run().get + 1 | ||
|
||
def p1(x: Int=>Int): Int = x(1) + 1 | ||
def p1_async(x: Int=>ComputationBound[Int]): Int = | ||
x(1).run().get + 1 | ||
|
||
} | ||
|
||
@Test | ||
def testApplyContextFunctionP1(): Unit = { | ||
var x = 0 | ||
val c = async[ComputationBound] { | ||
val a = await(T1.cbi(2)) | ||
O { | ||
//val _ = ((x:Int) => x + await(T1.cbi(3))) | ||
val q = O.p1( x => x+ await(T1.cbi(3)) ) | ||
if (false) then | ||
println(s"ctx=${summon[Context]}") | ||
a + q | ||
} | ||
} | ||
//println(s"run=${c.run()}") | ||
assert(c.run() == Success(7)) | ||
} | ||
|
||
|
||
@Test | ||
def testApplyContextFunctionP0(): Unit = { | ||
var x = 0 | ||
val c = async[ComputationBound] { | ||
val a = await(T1.cbi(2)) | ||
O { | ||
//val _ = ((x:Int) => x + await(T1.cbi(3))) | ||
val q = O.p0(await(T1.cbi(3))) | ||
if (false) then | ||
println(s"ctx=${summon[Context]}") | ||
a + q | ||
} | ||
} | ||
assert(c.run() == Success(6)) | ||
} | ||
|
||
|
||
} |