Skip to content

Instantly share code, notes, and snippets.

package cont
import scala.util.Try
abstract class Cont[A] {
def run[R](cont: A => R): R
def map[B](fn: A => B): Cont[B] = {
val self = this
new Cont[B] {def run[R](cont: B => R) = self.run(cont compose fn)}
}
@yellowflash
yellowflash / RegExp.scala
Last active September 1, 2018 01:06
Regex Engine which runs in `O(mn)` Glushkov automaton
sealed trait RegExp {
def isFinal:Boolean
def acceptsEmpty:Boolean
def shift(prev:Boolean, character:Char):RegExp
def matches(str:String) =
if(str.isEmpty) this.acceptsEmpty
else str.foldLeft(this.shift(true, str.head))(_.shift(false,_)).isFinal
}
object Epsilon extends RegExp {
trait Functor[T, F[_]] { self: F[T] =>
def map[K](fn: T => K): F[K]
}
sealed trait Optional[+T] extends Functor[T, Optional]
case class Maybe[T](value:T) extends Optional[T] {
override def map[K](fn: T => K) = Maybe(fn(value))
}
case object Nope extends Optional[Nothing] {
package skiequivalence
sealed trait SKIExpression {
def convert:SKIExpression
def freeVariables:Set[TermVariable]
}
case class TermVariable(variable:String) extends SKIExpression {
override def convert = this
override def freeVariables = Set(this)
import Data.List
import Data.Char
data Prop = Const Bool
|Var Char
|Not Prop
|And Prop Prop
|Implies Prop Prop
deriving Show