Skip to content

Instantly share code, notes, and snippets.

Rob Dickens robcd

Block or report user

Report or block robcd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:3313553
// In the following code, Get is a type which has previously been called State - a name which
// the author found to be confusing, since instances aren't actually states!
//
// Instances are in fact functions which obtain (get) a value that depends on some state.
//
// The following code demonstrates using a Get to set as well as get!
//
// claim: even this is less confusing than using the name State!
//
// N.B. Here, 'State' is the type of the er, state.
@robcd
robcd / gist:2787106
Created May 25, 2012
Variation on sample program of SftI Ex 22.5, for future reference!
View gist:2787106
import scala.util.continuations._
object Main extends App {
val a = "Mary was a little lamb".split(" ")
type Next = (Boolean => String)
var next: Next = null
val firstResultOfShiftBlock = reset {
var i = 0
while (i < a.length) {
@robcd
robcd / gist:2507381
Created Apr 27, 2012
A solution to SftI Ex 21.3
View gist:2507381
trait Factorial {
def ! : BigInt
// ^ space required!
}
object Factorial {
implicit def Int2Factorial(n: Int): Factorial = new Factorial {
def ! = {
if (n < 0) throw new RuntimeException("unable to compute factorial of negative number")
@annotation.tailrec
@robcd
robcd / gist:2028683
Created Mar 13, 2012
A solution to SftI Ex 19.9
View gist:2028683
import util.parsing.combinator.RegexParsers
class RegexProgRunner extends RegexParsers {
val number = "-?[0-9]+".r
val varName = "[a-zA-Z_][a-zA-Z_0-9]*".r
var vars = Map[String, Double]()
def start: Parser[Any] = prog(true)
def prog(b: Boolean): Parser[Any] = rep1(statement(b))
@robcd
robcd / 3nightclubs.scala
Created Sep 26, 2011 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
View 3nightclubs.scala
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0) */
import scalaz._
import Scalaz._
object Sobriety extends Enumeration {
You can’t perform that action at this time.