Skip to content

Instantly share code, notes, and snippets.

View kmizu's full-sized avatar

Kota Mizushima kmizu

View GitHub Profile
@kmizu
kmizu / list5.rs
Last active August 29, 2015 14:22
use std::fmt;
use List::{Cons, Nil};
use std::sync::Arc;
#[derive(PartialEq, Clone)]
enum List<T> {
Cons(T, Arc<List<T>>),
Nil
}
@kmizu
kmizu / list6.rs
Created May 27, 2015 22:38
module lists, which contains List-related functions
use lists::{filter, new_list};
mod lists {
use std::fmt;
use lists::List::{Cons, Nil};
use std::sync::Arc;
#[derive(PartialEq, Clone)]
pub enum List<T> {
Cons(T, Arc<List<T>>),
use lists::{contains, new_list};
mod lists {
use std::fmt;
use lists::List::{Cons, Nil};
use std::sync::Arc;
#[derive(PartialEq, Clone)]
pub enum List<T> {
Cons(T, Arc<List<T>>),
use lists::{count, new_list};
mod lists {
use std::fmt;
use lists::List::{Cons, Nil};
use std::sync::Arc;
#[derive(PartialEq, Clone)]
pub enum List<T> {
Cons(T, Arc<List<T>>),
object NullAsInstanceOfInt {
def main(args: Array[String]): Unit = {
println { null.asInstanceOf[Int] == 0 } // true
println{ null.asInstanceOf[Int] + 1 } // 1
println{ null.asInstanceOf[Int] } // null
println{ val x = null.asInstanceOf[Int]; x } // 0
}
}
package controllers
import play.api.mvc._
object Application extends Controller {
def upload = Action(parse.multipartFormData) {
request =>
if (request.body.files.isEmpty) BadRequest("Invalid file!")
else if (request.body.asFormUrlEncoded.isEmpty) BadRequest("Invalid data!")
else Ok("Everything is okay!")
@kmizu
kmizu / Hello.scala
Created July 1, 2015 14:31
Hello, World in dotty
object Hello {
def main(args: Array[String]): Unit = {
foo()
}
@inline def foo() = println("Foo")
}
@kmizu
kmizu / TLambda.scala
Created July 2, 2015 13:59
Is typing undecidable trulely ?
object TLambda {
trait Lambda { type apply[a <: Lambda] <: Lambda }
type Y = Lambda {
type apply[f <: Lambda] = (Lambda {
type apply[proc <: Lambda] = f#apply[Lambda {
type apply[arg <: Lambda] = proc#apply[proc]#apply[arg]
}]
})#apply[Lambda {
type apply[proc <: Lambda] = f#apply[Lambda {
type apply[arg <: Lambda] = proc#apply[proc]#apply[arg]
import scala.io._
import scala.util.parsing.combinator.syntactical._
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Label
import org.objectweb.asm.Opcodes._
object Calculator extends StandardTokenParsers {
lexical.delimiters ++= List(
"(", ")","+","-","*","/", ">", "<", ">=", "<=", "=", ";"
import scala.xml._
object Attrs {
def unapplySeq(data: MetaData): Option[Seq[(String, String)]] = {
Some(data.map{(m:MetaData) => (m.key, m.value(0).text)}.toList)
}
def main(args: Array[String]) {
val foo = <foo a="1" b="2" c="3"/>
//困ったことに、XMLリテラルは属性の順番を保存してくれないので、
//ファイルから読み込むとか別の方法が必要
//XML.loadStringとかだと属性が逆順で読み込まれるっぽい