This file contains 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
object test { | |
trait M[X[_]] { | |
def map[A, B](a: X[A])(f: A => B): X[B] | |
} | |
trait Parsers { | |
trait Parser[Y] { | |
def map[B](f: Y => B): Parser[B] = null | |
} | |
} |
This file contains 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
object test { | |
trait M[X[_]] { | |
def map[A, B](a: X[A])(f: A => B): X[B] | |
} | |
trait Parsers { | |
trait Parser[Y] { | |
def map[B](f: Y => B): Parser[B] = null | |
} | |
} |
This file contains 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 org.jscience.mathematics.number.LargeInteger | |
import com.google.caliper.{ Param, SimpleBenchmark } | |
class FactorialBenchmark extends SimpleBenchmark { | |
// Borrowed from https://github.com/sirthias/scala-benchmarking-template. | |
def repeat[@specialized A](reps: Int)(snippet: => A) = { | |
val zero = 0.asInstanceOf[A] | |
var i = 0 |
This file contains 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 dispatch._ | |
import java.io.ByteArrayInputStream | |
import java.util.zip.ZipInputStream | |
import scala.util.parsing.json.JSON.{ parseFull => parseJson } | |
val headers = Map("content-type" -> "application/x-www-form-urlencoded") | |
val tokenUrl = url("https://silvermaple.pti.indiana.edu:25443/oauth2/token") | |
val volumesUrl = url("https://silvermaple.pti.indiana.edu:25443/data-api/volumes/") | |
def tokenParams(id: String, secret: String) = Map( |
This file contains 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
scala> import scalaz._, Scalaz._ | |
import scalaz._ | |
import Scalaz._ | |
scala> val a: String \/ Int = "x".left | |
a: scalaz.\/[String,Int] = -\/(x) | |
scala> val b: String \/ Int = "y".left | |
b: scalaz.\/[String,Int] = -\/(y) |
This file contains 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.util.parsing.combinator._ | |
import scalaz._, Scalaz._ | |
trait ExtraStateParsers[S] { this: Parsers => | |
type ESP[A] = StateT[Parser, S, A] | |
protected implicit def monadInstance: Monad[Parser] | |
protected implicit def monadStateInstance = | |
implicitly[MonadState[({type F[T, +B] = StateT[Parser, T, B]})#F, S]] |
This file contains 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.util.parsing.combinator._ | |
import scalaz._, Scalaz._ | |
trait ExtraStateParsers[S] { this: Parsers => | |
type ESP[A] = StateT[Parser, S, A] | |
protected implicit def monadInstance: Monad[Parser] | |
protected implicit def monadStateInstance = | |
implicitly[MonadState[({type F[T, +B] = StateT[Parser, T, B]})#F, S]] |
This file contains 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
/** | |
* We can use the Scala type system (with help from Miles Sabin's Shapeless | |
* library) to solve the bank account number validation problem in the second | |
* user story of the KataBankOCR kata on Coding Dojo: | |
* | |
* http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR | |
* | |
* By Travis Brown in response to a question by Paul Snively on the Shapeless | |
* Dev mailing list: | |
* |
This file contains 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
/** | |
* Type-level Tower of Hanoi | |
* by Travis Brown | |
* | |
* Note: not optimal, and probably won't work for some valid inputs. | |
* Tested with Scala 2.9.2 and Shapeless 1.2.3. | |
*/ | |
import shapeless._, Nat._ |
This file contains 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 shapeless._ | |
trait Flatten[I, O <: HList] { | |
def apply(i: I): O | |
} | |
trait FlattenLow { | |
implicit def otherFlatten[I] = new Flatten[I, I :: HNil] { | |
def apply(i: I) = i :: HNil | |
} |
OlderNewer