Skip to content

Instantly share code, notes, and snippets.

class Foo
object Main {
def hoge[A](fooCompatible: A)(implicit converter: Converter[A]) = {
}
def main(args: Array[String]) {
hoge(new Foo)(Converter.identity) // この行を消すと下の行もエラーになる
hoge(new Foo)
}
// これは通る
class Foo {
def foo {
implicitly[Bar](Bar.bar)
implicitly[Bar]
}
}
class Bar
@taku0
taku0 / MyJDBCWrapper.scala
Created September 16, 2011 16:26
オレオレJDBCラッパのプロトタイプ
import java.sql.ResultSet
import java.sql.PreparedStatement
import java.sql.Connection
import java.sql.Types
trait RowParser[A] extends ((ResultSet, Int) => A) {
def arity: Int
def apply(resultSet: ResultSet, index: Int): A
}
@taku0
taku0 / my_jdbc_wrapper.rb
Created September 17, 2011 03:43
オレオレJDBCラッパのプロトタイプ Ruby版
# -*- coding: utf-8 -*-
class RowParser
end
class BlockParser < RowParser
def initialize(*parsers, &block)
@block = block
@parsers = parsers
end
@taku0
taku0 / Main.java
Created October 13, 2011 14:31
数値がオブジェクトであるような体系で、同一でないオブジェクトが数値として等しくなる例
import java.util.concurrent.Callable;
public class Main {
public static void main(String[] args) {
Number two1 = new Succ(new Succ(new Zero()));
Number two2 = new Succ(new Succ(new Zero()));
System.out.println(two1 == two2);
System.out.println(two1.myEquals(two2));
}
@taku0
taku0 / Diamond.scala
Created October 15, 2011 16:01
Scalaでtypeをダイアモンド継承する際に綺麗に書けない
trait A {
type X <: AA
trait AA
}
trait B extends A {
type X <: AA with BB
trait BB
}
@taku0
taku0 / regex_benchmark.rb
Created October 22, 2011 03:40
Ruby regex benchmark
require "benchmark"
def test(benchmark, pattern, text, run)
benchmark.report(text.length.to_s) do
run.times do
text = text.gsub(pattern, " ")
end
end
end
pattern = /[-_.0-9A-Za-z]+@[-_0-9A-Za-z]+[-_.0-9A-Za-z]+/
@taku0
taku0 / Main.scala
Created December 6, 2011 14:13
scala.collection.mutable.HashSet遅い?
import scala.collection.JavaConverters._
object Main extends App {
def bench(set1: java.util.Set[Int], set2: java.util.Set[Int]) = {
val start = System.nanoTime
var sum = 0
0.until(10).map(_ => {
val diff = new java.util.HashSet[Int]
@taku0
taku0 / Foo.scala
Created February 25, 2012 04:57
overloading by return type
class Foo {
def foo(implicit x: X) = x
def foo(implicit y: Y) = y
class X
class Y
implicit val x_ = new X
implicit val y_ = new Y
newtype MyNum a r = MyNum { unNum :: ((MyNum a r -> r) -> r -> r) }
zero :: MyNum a r
zero = MyNum (\f x -> x)
mySucc :: MyNum a r -> MyNum a r
mySucc n = MyNum (\f x -> f n)
one :: MyNum a r
one = mySucc zero