Skip to content

Instantly share code, notes, and snippets.

View kmizu's full-sized avatar

Kota Mizushima kmizu

View GitHub Profile
@kmizu
kmizu / Undecidable.scala
Created July 1, 2018 21:07
Scala's existential type cannot emulate Java's Wildcard
trait Z
trait N[X]
trait L[X]
trait Qlr[X]
trait Qrl[X]
trait E[X] extends AnyRef with Qlr[N[_ >: Qr[_ >: E[_ >: E[_ >: X]]]]] with Qrl[N[_ >: Ql[_ >: E<_ >: E[_ >: X]]]]
trait Ql[X] extends AnyRef with L[N[_ >: Ql[_ >: L[_ >: N[_ >: X]]]]] with E[Qlr[_ >: N[_ >: X]]]
trait Qr[X] extends AnyRef with L[N[_ >: Qr[_ >: L[_ >: N[_ >: X]]]]] with E[Qrl[_ >: N[_ >: X]]]
object Undecidable {
def doIt(v: Qr[_ >: E[_ >: E[_ >: Z]]]): L[_ >: N[_ >: L[_ >: N[_ >: L[_ >: N[_ >: E[_ >: E[_ >: Z]]]]]]]] = v
@kmizu
kmizu / file0.scala
Last active June 11, 2018 06:21
Scala考古学:短絡評価は名前渡しとして実装されているか? ref: https://qiita.com/kmizu/items/0925ab2b642992bb4cb0
package scala
abstract sealed class Boolean extends AnyVal {
def && (p: => Boolean): Boolean = // boolean and
if (this) p else false
def || (p: => Boolean): Boolean = // boolean or
if (this) true else p
def & (x: Boolean): Boolean = // boolean strict and
if (this) x else false
def | (x: Boolean): Boolean = // boolean strict or
if (this) true else x
@kmizu
kmizu / O.scala
Created April 25, 2018 16:18
Overloading by arity of methods
object O {
def f: Int = 0
def f(x: Int): Int = x
def main(args: Array[String]): Unit = {
println(f)
println(f(3))
}
}
@kmizu
kmizu / parser_combinator.dart
Created March 31, 2018 02:54
Parser Combinator in Dart
abstract class ParseResult<T> {
String next;
ParseResult(this.next) {}
T get value;
bool get successful;
}
class Pair<T1, T2> {
T1 item1;
@kmizu
kmizu / console1.txt
Last active March 29, 2018 02:28
Type inference of dartanalyzer is weak ?
[mizushima]$ dartanalyzer generics.dart
Analyzing generics.dart...
error • Missing parameter type for 'x' at generics.dart:13:37 • strong_mode_implicit_dynamic_parameter
1 error found.
@kmizu
kmizu / file0.txt
Created March 25, 2018 03:03
fold / reduce のススメ(あるいは高階関数のススメ) ref: https://qiita.com/kmizu/items/c951d5d50c351f39d46c
array.reduce((sum, x) => sum + x, 0) // 0はあえて明示した
@kmizu
kmizu / Main.scala
Created February 15, 2018 17:59
SAM-convertible type and Function type
package com.github.kmizu.play_json_example
import play.api.libs.json._
object Main {
implicit class RichWrites[A](w: Writes[A]) {
def ignore(ignoreFields: String*): Writes[A] = {
w.transform{
case JsObject(fields) => JsObject(fields.filterNot {
case (k, _) => ignoreFields.contains(k)
})
@kmizu
kmizu / file0.txt
Last active January 24, 2018 11:09
Nemerleで n == 1 && n == 2 && n == 3をtrueにする ref: https://qiita.com/kmizu/items/77c1f4244502c4dd4058
using Nemerle.Compiler;
macro @==(lhs, rhs) {
<[
true
]>
}
@kmizu
kmizu / example.ebnf
Created December 17, 2017 12:35
Test
tyseq ::= tywotseq
| (ty1,...,tyn)
ty ::= tywotseq
| tyseq longtycon
| ( ty )
tywotseq ::= tyvar
| { <tyrow> }
| tywoarrow -> ty
| ( ty )
@kmizu
kmizu / bench.py
Created November 29, 2017 05:25
Python VS. Scala
import time
def main():
start = time.time()
z = 0
for i in range(0, 100000000):
z += 1
print(z)
end = time.time()
print(end - start)