Skip to content

Instantly share code, notes, and snippets.

@anrizal06
anrizal06 / Proposition.scala
Created September 24, 2011 22:24
Naîve Semantic Tableau for Propositional Logic
package propositional
import scala.annotation.tailrec
sealed abstract class Formula {
def ∧(q:Formula) = Conjunction(this, q)
def ∨(q:Formula) = Disjunction(this,q)
def →(q:Formula) = Implication(this,q)
@anrizal06
anrizal06 / gist:1195982
Created September 5, 2011 21:38
Implementation of solution 3 from (Pope, 2010 ?) in Scala
// To simplify the implementation, foldr_ is introduced. It is the foldr function with a modification in
// combine parameter. Instead of (A, =>B) => B, combine has type (A, B, Stream[A])=>B.
// This makes combine has an easy access to the stream being processed.
// There might be another way to implement the solution, but this one is the one that comes into my head so far.
def foldr_[A, B]( combine: (A, =>B, Stream[A]) => B, base: B)( xs: Stream[A]): B = {
if (xs.isEmpty)
base
else
combine(xs.head, foldr_(combine, base)(xs.tail), xs)
}
@anrizal06
anrizal06 / gist:1079163
Created July 12, 2011 22:42
Creating List with elements are of type A and B consecutively
class MyA[A, B](val head: A, val tail: Option[MyA[B, A]]) {
override def toString() = head + tail.map( "," + _.toString).getOrElse("")
def ::( x: B) = new MyA(x, Some(this))
}
object MyA {
def apply[A,B](value: A) : MyA[A, B] = new MyA(value, None)
}
// examples: