This file contains hidden or 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
import Data.List | |
import Data.Char | |
data Prop = Const Bool | |
|Var Char | |
|Not Prop | |
|And Prop Prop | |
|Implies Prop Prop | |
deriving Show |
This file contains hidden or 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
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) |
This file contains hidden or 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
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] { |
This file contains hidden or 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
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 { |
This file contains hidden or 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
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)} | |
} |
This file contains hidden or 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
module Godel.Core where | |
import Control.Monad (bind, pure) | |
import Control.Monad.Eff.Console (log) | |
import Data.Either (Either(..)) | |
import Data.Eq (class Eq, (==)) | |
import Data.Map (Map, empty, insert, lookup) | |
import Data.Maybe (Maybe(..)) | |
import Data.Show (class Show, show) | |
import Prelude (otherwise, negate, (+), (-), (>=), ($), (<>)) |
This file contains hidden or 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
class Map { | |
constructor(loadfactor = 0.7) { | |
this.size = 0; | |
this.loadfactor = 0.7; | |
this.entries = new Array(1); | |
} | |
put(key, value) { | |
this.resizeIfNecessary(); | |
for(var i = key.hashCode();; i++) { |
This file contains hidden or 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
class Regex { | |
constructor(matchesEmpty) { | |
this.matchesEmpty = matchesEmpty; | |
} | |
derivativeBy(ch) { | |
throw "Not implemented"; | |
} | |
matches(str) { |
This file contains hidden or 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
import scala.annotation.tailrec | |
import scala.collection.mutable | |
case class Point(x: Int, y: Int) { | |
def geoHash(precision: Int): BigInt = { | |
@tailrec | |
def hash(minX: Int, maxX: Int, minY: Int, maxY: Int, prec: Int, sofar: BigInt) : BigInt = { | |
if(prec == 0) return sofar; | |
val quadrant = if((minX + maxX)/2 < x) { | |
if((minY + maxY)/2 < y) 0 else 1 |
This file contains hidden or 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
{-# LANGUAGE NoMonomorphismRestriction #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Diagrams.Prelude | |
import Diagrams.Backend.SVG.CmdLine | |
appendsEx k n c = appends c (zip (iterateN n (rotateBy (1/(fromIntegral k))) unitX) (repeat circ)) | |
circ = (circle 1 # fc red # lc white # lwL 0.25) | |
sides = 6 |
OlderNewer