This file contains hidden or 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 java.io.File | |
import scala.io.Source | |
import scala.util.matching.Regex | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input.{Position, NoPosition} | |
sealed abstract class Insn extends ( CED => CED ){ | |
val pos:Position | |
} | |
case class App( m:Int, n:Int, pos:Position ) extends Insn{ |
This file contains hidden or 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 com.github.everpeace | |
/** | |
* commented by @kmizu | |
* @author everpeace _at_ gmail _dot_ com | |
* @date 11/09/23 | |
*/ | |
class { | |
def main(args:Array[String]):Unit = { |
This file contains hidden or 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
//To compile this, "-P:continuations:enable" option is needed. | |
import scala.util.continuations._ | |
import scala.collection._ | |
object Generator { | |
abstract sealed class Computation[+A] | |
case class Yielded[A](k: Unit => Computation[A], v: A) extends Computation[A] | |
case object Done extends Computation[Nothing] | |
type yieldable[A] = cps[Computation[A]] |
This file contains hidden or 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
//scalac -P:continuations:enable MarshallingContinuations.scala | |
import scala.util.continuations._ | |
import scala.util.control.Exception._ | |
import java.io._ | |
object MarshallingContinuations { | |
var y = 10 | |
def using[A <: Closeable, B](resource: A)(block: A => B): B = try { | |
block(resource) | |
} finally { |
This file contains hidden or 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.testing.Benchmark | |
import scala.collection.immutable.NumericRange | |
object FactParallel extends Benchmark { | |
def run { | |
def fac(n: BigInt): BigInt = NumericRange(BigInt(1), n, BigInt(1)).foldLeft(BigInt(1))(_*_) | |
(1 to 2000).par.map{x => /* printf("x = %02d:%s%n", x, Thread.currentThread.toString); */ fac(x) } | |
} | |
} |
This file contains hidden or 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
val people = Iterator.continually(readLine()).takeWhile(_ != null).toArray | |
val random = new scala.util.Random(System.currentTimeMillis) | |
println("elected person is: " + people(random.nextInt(people.length))) |
This file contains hidden or 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 java.io.StringReader | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input._ | |
import scala.util.parsing.combinator.syntactical._ | |
import java.util.Properties | |
object NestablePropertyParser { | |
object Parser extends StandardTokenParsers { | |
lexical.delimiters ++= List("{", "}", "=") | |
def parse(input: String): Either[String, Properties] = { |
This file contains hidden or 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
//This implementation is a porting of naive continuation monad in Haskell in "All About Monads" pages. | |
class Cont[R, +A](val runCont: (A => R) => R) { | |
def map[B](f: A => B): Cont[R, B] = { | |
new Cont[R, B](k => runCont(a => Cont.ret[R, B](f(a)).runCont(k))) | |
} | |
def flatMap[B](f: A => Cont[R, B]) :Cont[R, B] = { | |
new Cont[R, B](k => runCont(a => f(a).runCont(k))) | |
} | |
} |
This file contains hidden or 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 TF { | |
type Apply[A] | |
} | |
type Curry2[F[_, _]] = TF { type Apply[X] = TF { type Apply[Y] = F[X, Y] } } | |
type Curry3[F[_, _, _]] = TF { type Apply[X] = Curry2[(TF { type Apply[Y, Z] = F[X, Y, Z] })#Apply] } | |
// ... | |
type CurriedMap = Curry2[Map] | |
val x: CMap#Apply[String]#Apply[Int] = Map("x" -> 1, "y" -> 1) //It is valid code. |
This file contains hidden or 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.DynamicVariable | |
/** | |
* A concise JSON DSL in Scala. | |
* When you want to use, only | |
* import Jsson._ is needed. | |
* Note that this program change the semantics of standard -> operator. | |
* I recommend that you use enclosing block with Jsson as followings: | |
* { | |
* import Jsson._ | |
* val obj = %{ |