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 play.api.libs.json._ | |
import play.api.libs.json._ | |
scala> case class Test[A: Writes](a: A) | |
defined class Test | |
scala> implicit def testWrites[A: Writes] = Json.writes[Test[A]] | |
<console>:12: error: No apply function found matching unapply parameters | |
implicit def testWrites[A: Writes] = Json.writes[Test[A]] | |
^ |
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
> ++2.10.4 | |
[info] Setting version to 2.10.4 | |
[info] Set current project to wartremover (in build file:/Users/georgii/workspace/wartremover/) | |
> console | |
[info] Updating {file:/Users/georgii/workspace/wartremover/}wartremover... | |
[info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
[info] Done updating. | |
[info] Compiling 24 Scala sources to /Users/georgii/workspace/wartremover/target/scala-2.10/classes... | |
[info] Starting scala interpreter... | |
[info] |
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> trait Assoc[K] { type V ; val value: V } | |
defined trait Assoc | |
scala> def mkAssoc[K, V0](k: K, v: V0): Assoc[k.type] { type V = V0 } = | |
| new Assoc[k.type] { type V = V0 ; val value = v } | |
mkAssoc: [K, V0](k: K, v: V0)Assoc[k.type]{type V = V0} | |
scala> def lookup[K](k: K)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value | |
lookup: [K](k: K)(implicit assoc: Assoc[k.type])assoc.V |
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 scala.collection.mutable._ | |
object Bf extends Application { | |
private val data = ArrayBuffer[Char]() // TODO fill | |
private var pointer = 0 | |
private var in: String = "" | |
private var _init = false | |
private def getNextInput() = { |
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
trait Monad[+M[_]] { | |
def unit[A](a: A): M[A] | |
def bind[A, B](m: M[A])(f: A => M[B]): M[B] | |
} | |
// probably only works in Scala 2.8 | |
implicit def monadicSyntax[M[_], A](m: M[A])(implicit tc: Monad[M]) = new { | |
private val bind = tc.bind(m) _ | |
def map[B](f: A => B) = bind(f compose tc.unit) |
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
trait ~>[F[_],G[_]] { | |
def apply[A](a: F[A]): G[A] | |
} | |
type Id[A] = A | |
def apply[B](f: Id ~> List, b: B, s: String): (List[B], List[String]) = (f(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
// haskell: | |
// data Bool = False | True | |
// scala | |
sealed abstract class Bool | |
case object True extends Bool | |
case object False extends Bool |
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
-- First | |
return a >>= k = k a | |
-- Second | |
m >>= return = m | |
-- Third | |
m >>= (\x -> f x >>= g) = (m >>= f) >>= g |
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
reset { | |
// A | |
shift { cf: (Int=>Int) => | |
// B | |
val eleven = cf(10) | |
// E | |
println(eleven) | |
val oneHundredOne = cf(100) | |
// H | |
println(oneHundredOne) |
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
-- static Peano constructors and numerals | |
data Zero | |
data Succ n | |
type One = Succ Zero | |
type Two = Succ One | |
type Three = Succ Two | |
type Four = Succ Three |
OlderNewer