-
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.
enforse lazy evaluation of infinite sequenc in logic
- Loading branch information
Showing
7 changed files
with
329 additions
and
191 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
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,46 @@ | ||
package logic | ||
|
||
import cps.* | ||
import cps.monads.{*, given} | ||
import logict.{*,given} | ||
|
||
import org.junit.Test | ||
|
||
|
||
class GrandParentsTest { | ||
|
||
@Test | ||
def testLogicM() = { | ||
import GrandParentsTest.* | ||
val r = grandParent[LogicM]("Anne").observeAll | ||
println(s"GrandParentTest: r=$r") | ||
assert(r.size == 2) | ||
assert(r.contains("Sarah")) | ||
assert(r.contains("Arnold")) | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
object GrandParentsTest { | ||
|
||
case class IsParentOf(parent:String, child:String) | ||
|
||
def parents = Seq( | ||
IsParentOf("Sarah", "John"), | ||
IsParentOf("Arnold", "John"), | ||
IsParentOf("John", "Anne"), | ||
) | ||
|
||
def grandParent[M[_]:CpsLogicMonad](name:String):M[String] = reify[M]{ | ||
// TODO: fill bug report in dotty. | ||
// shopuld be search | ||
import cps.CpsMonadConversion.given | ||
val IsParentOf(p,c) = reflect(all(parents)) | ||
guard(c == name) | ||
val IsParentOf(gp,_) = reflect(all(parents.filter(_.child == p))) | ||
gp | ||
} | ||
|
||
} |
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,41 @@ | ||
package logic | ||
|
||
import scala.concurrent.duration.* | ||
import scala.util.* | ||
import cps.* | ||
import logict.* | ||
import org.junit.Test | ||
|
||
class LogicTTest { | ||
|
||
import LogicTTest.* | ||
|
||
@Test | ||
def testNatCB():Unit = { | ||
|
||
val cbNat = nats[[A] =>> LogicT[ComputationBound,A]] | ||
|
||
val cb4 = cbNat.observeN(4) | ||
assert(cb4.run(1.second) == Success(Seq(1,2,3,4))) | ||
|
||
val cbOdd = odds[[A] =>> LogicT[ComputationBound,A]] | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
object LogicTTest { | ||
|
||
def nats[M[_]](using m: CpsLogicMonad[M]): M[Int] = | ||
m.pure(1) |+| reify[M] { 1 + reflect(nats) } | ||
|
||
def odds[M[_]](using m: CpsLogicMonad[M]): M[Int] = | ||
m.pure(1) |+| reify[M] { 2 + reflect(odds) } | ||
|
||
|
||
|
||
|
||
} |
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
Oops, something went wrong.