Instantly share code, notes, and snippets.

# Rob Dickensrobcd

• Sort options
Created Aug 10, 2012
Get vs State
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.
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) {
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
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))
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.