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
case class B() | |
object App extends A { | |
def main(args: Array[String]): Unit = { | |
printImplicit | |
} | |
def printImplicit(implicit b: B) = b | |
} |
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
:- module ml. | |
:- interface. | |
:- import_module io. | |
:- pred main(io::di, io::uo) is cc_multi. | |
:- implementation. | |
:- import_module bool, int, string, list, pair, assoc_list, lex, regex. | |
main(!IO) :- | |
Lexer = lex.init(lexemes, lex.read_from_stdin, ignore(space)), | |
State0 = lex.start(Lexer, !.IO), |
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 language.experimental.macros | |
package object macros |
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> showRaw(reify(Nil.::("hoge").::(123)).tree).length | |
res0: Int = 188 | |
scala> showRaw(reify(123 :: "hoge" :: Nil).tree).length | |
res1: Int = 392 |
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.language.dynamics | |
import scala.util.DynamicVariable | |
sealed trait Node { | |
def render: String | |
} | |
case class ElementNode(name: String, attributes: Map[String, String], children: List[Node]) extends Node { | |
def render = { |
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.language.dynamics | |
import scala.util.DynamicVariable | |
sealed trait Node { | |
def toXml: String | |
} | |
case class ElementNode(name: String, attributes: Map[String, String], children: List[Node]) extends Node { | |
def toXml = { |
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 Macros { | |
def tbtest = macro tbtestImpl | |
def tbtestImpl(c:Context) = { | |
import c.universe._ | |
import scala.reflect.runtime.{currentMirror => cm} | |
import scala.reflect.runtime.{universe => ru} | |
val toolBox = cm.mkToolBox() | |
val importer = c.universe.mkImporter(ru) |
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> Some(1).map(_ :: Nil) getOrElse Nil | |
res0: List[Int] = List(1) | |
scala> Some(1).fold(Nil)(_ :: Nil) | |
<console>:8: error: type mismatch; | |
found : List[Int] | |
required: scala.collection.immutable.Nil.type | |
Some(1).fold(Nil)(_ :: Nil) | |
^ |
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
package surpassing.problem | |
object Specification { | |
def msc[A: Ordering](xs: List[A]) = (for (z :: zs <- tails(xs)) yield scount(z, zs)).max | |
def scount[A](x: A, xs: List[A])(implicit o: Ordering[A]) = { | |
import o._ | |
xs.filter(x < _).length | |
} |
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
package smallest.free.number | |
trait Bench { | |
def bench[A](body: => A) = { | |
val start = System.currentTimeMillis() | |
val result = body | |
val end = System.currentTimeMillis() | |
println(s"time: ${end - start}") | |
result | |
} |
NewerOlder