From ba9621fc48ff84e01d9f70d076cc912b8185729d Mon Sep 17 00:00:00 2001 From: Jake Donham Date: Mon, 2 May 2011 21:24:19 -0700 Subject: [PATCH] fixes --- _code/scala-logic/Bridge.scala | 2 +- ...-04-06-logic-programming-in-scala.markdown | 28 +++++++++++++++++++ ...4-29-logic-programming-in-scala-2.markdown | 5 +++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/_code/scala-logic/Bridge.scala b/_code/scala-logic/Bridge.scala index 34f46ab..4de7791 100644 --- a/_code/scala-logic/Bridge.scala +++ b/_code/scala-logic/Bridge.scala @@ -1,4 +1,4 @@ -class Bridge(val Logic: Logic) { +class Bridge[L <: Logic](val Logic: L) { import Logic._ object Person extends Enumeration { diff --git a/_posts/2011-04-06-logic-programming-in-scala.markdown b/_posts/2011-04-06-logic-programming-in-scala.markdown index e82e039..916142b 100644 --- a/_posts/2011-04-06-logic-programming-in-scala.markdown +++ b/_posts/2011-04-06-logic-programming-in-scala.markdown @@ -510,3 +510,31 @@ scala> run[List[b.State]](LogicList, b, b.search, 2) run[List[b.State]](LogicList, b, b.search, 2) ^ {% endhighlight %} + +*Addendum addendum* + +Some further advice from Jorge Ortiz: the specific type of `Logic` +(not just `Logic.type`) can be exposed outside `Bridge` either through +polymorphism: + +{% highlight scala %} +class Bridge[L <: Logic](val Logic: L) { + ... +} + +val b = new Bridge(LogicList) +{% endhighlight %} + +or by defining an abstract value (this works the same if `Bridge` is a +trait): + +{% highlight scala %} +abstract class Bridge { + val Logic: Logic + ... +} + +val b = new Bridge { val Logic = LogicList } +{% endhighlight %} + +So we can compose uses of `T` but it remains abstract. diff --git a/_posts/2011-04-29-logic-programming-in-scala-2.markdown b/_posts/2011-04-29-logic-programming-in-scala-2.markdown index 4324c58..c2f73fb 100644 --- a/_posts/2011-04-29-logic-programming-in-scala-2.markdown +++ b/_posts/2011-04-29-logic-programming-in-scala-2.markdown @@ -145,7 +145,7 @@ from the `bind`), and the failure continuation in force at the point `a` was generated (which succeeds with the next available alternative from `f(a)`). -For `map` things are simpler, since `f(a)` returns a single value +For `apply` things are simpler, since `f(a)` returns a single value rather than a choice of alternatives: we succeed immediately with the returned value. @@ -566,5 +566,8 @@ scala> run(nat, 100000) ^C {% endhighlight %} +See the complete code +[here](https://github.com/jaked/ambassadortothecomputers.blogspot.com/tree/master/_code/scala-logic). + Next time we'll thread state through this backtracking logic monad, and use it to implement unification.