Skip to content

Instantly share code, notes, and snippets.

@koher
koher / MultiValuesTestServlet.java
Created March 26, 2010 11:50
GAE/JのLow-Level APIで複数値プロパティを扱う例
package org.koherent.appengine.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.ServletException;
@koher
koher / gist:617a51f3474a9ffc157b
Last active August 29, 2015 14:02
Swift's Polymorphism Test
protocol O {
func f() -> String
}
struct A : O {
func f() -> String {
return "a"
}
}
@koher
koher / gist:834e0e8b5a19d316b1cf
Created June 22, 2014 11:28
Conceptual Implementations of Swift's Array and Dictionary
struct Array2<T> {
var buffer: Buffer<T>
var count: Int
init() {
buffer = Buffer()
count = 0
}
init(_ elements: T...) {
@koher
koher / gist:81c3d71a03c5caaed515
Created September 19, 2014 17:43
Javaで?を使わずにListがCovariantであるように振る舞わせると・・・
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.lang.System.out;
public class VarianceTest {
static class Animal {
}
@koher
koher / gist:c8db7b243e2ad347a165
Created June 23, 2015 02:16
Higher-oder functions/methods vs Control statements
a.map { b in
b.map { c in {
foo(b, c)
}
}
for b in a {
for c in b {
foo(b, c)
}

I want Swift's Either like ...

Suppose that Either is declared in the following way,

enum Either<T, U> {
    case Left(T)
    case Right(U)
}
@koher
koher / TreeMapGetGetsException.java
Created September 29, 2015 22:50
TreeMap#get gets ClassCastException
import java.util.*;
Map<String, Integer> map = new TreeMap();
map.put("abc", 123);
map.put("def", 456);
map.put("ghi", 789);
map.get("abc");
map.get(123); // java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
@koher
koher / something-is-wrong-in-swifts-type-system.md
Last active December 6, 2015 14:15
Something seems to be wrong in Swift's type system.

That was my misunderstanding especially about subtyping of value types.

@koher
koher / 1-throws-as-returning-a-result.md
Last active March 14, 2016 11:28
Proposal for error handling in Swift

throws as returning a Result

I think it would be great if throws -> Foo were a syntactic sugar of -> Result<Foo>. Without affecting existing codes, it makes it possible to go back and forth between Manual Propagation and Automatic Propagation seamlessly.

// I wish if the first `makeFoo` were
// a syntactic sugar of the second one
func makeFoo(x: Int) throws -> Foo {
  guard ... else {
 throw FooError()
# coding:utf-8
import tensorflow as tf
from random import choice
zun = -1.0
doko = 1.0
zun_length = 4
zundoko_length = zun_length + 1