Skip to content

Instantly share code, notes, and snippets.

Kota Mizushima kmizu

View GitHub Profile
View Nesting.scala
sealed abstract class Nest
case class NLeaf(code: Char) extends Nest
case class NList(elements: List[Nest]) extends Nest
def group(tokens: List[Char]): List[Nest] = {
def process(nest: List[Nest], acc: List[Nest], remain: List[Char]): (List[Nest], List[Nest], List[Char]) = {
remain match {
case Nil =>
(nest, Nil, Nil)
case ('(')::rest =>
@kmizu
kmizu / Hello.sc
Created Mar 7, 2019
Syntax Highlighting Test
View Hello.sc
object Hello extends App {
def main(args: Array[String]): Unit = {
println("Hello")
}
}
@kmizu
kmizu / T1.scala
Last active Feb 2, 2019
Write instances of Ordering[T] manually
View T1.scala
sealed abstract class T1
object T1 {
case class A(x: Int) extends T1
case class B(x: Double) extends T1
case class C(x: String) extends T1
implicit val ordA: Ordering[A] = (a, b) => a.x compare b.x
implicit val ordB: Ordering[B] = (a, b) => a.x compare b.x
implicit val ordC: Ordering[C] = (a, b) => a.x compare b.x
}
@kmizu
kmizu / PTailRecursion.scala
Created Jan 31, 2019
Partial tail-recursion is also optimized in scalac. It's an experiment for verifying the result of https://twitter.com/chrilves/status/1091032475801927680
View PTailRecursion.scala
object PTailRecursion {
def test(n: Int): Int =
if (n == 0)
test(n)
else
2 * test(n)
}
@kmizu
kmizu / file0.scala
Last active Jan 3, 2019
型なし言語のメリットを一言で書いてみる ref: https://qiita.com/kmizu/items/0892eca588088836967f
View file0.scala
sealed abstract class JsonValue
case class JsonObject(val members: Map[String, JsonValue]) extends JsonValue
case class JsonNumber(val value: Int) extends JsonValue
case class JsonString(val value: String) extends JsonValue
...
@kmizu
kmizu / file0.scala
Last active Nov 29, 2018
ScalaとJavaの境界におけるnullの扱い方 ref: https://qiita.com/kmizu/items/e4c7473f9ed831b5a1de
View file0.scala
import java.util
def useMap(config: util.Map[String, String]): Unit = {
// "version" に対応する値が必ずあるとわかっているとする
val version = config.get("version")
...
}
@kmizu
kmizu / file0.txt
Last active Nov 21, 2018
Erlangにパーザコンビネータで入門してみた ref: https://qiita.com/kmizu/items/459a982117a74e610b68
View file0.txt
root ::= expression;
expression ::= A;
A ::= M ( "+" M | "-" M)*;
M ::= P ( "*" P | "/" P)*;
P ::= "(" expression ")" | number;
number ::= [0-9]+;
@kmizu
kmizu / StringSwitch.java
Created Nov 12, 2018
String Switch in Java
View StringSwitch.java
public class StringSwitch {
public static void main(String[] args) {
String f = "foo";
switch(f) {
case "foo":
System.out.println("foo");
break;
case "bar":
System.out.println("foo");
break;
View fialyzer開発環境構築2018.md

構築する環境

  • Ubuntu 18.04 64bit
  • opam 2.0.0
  • ocaml 4.06.1 (最新は4.07だが、batteriesが未対応なので4.06で作る)
  • dune 1.2.1

準備

opam 2.0.0 のインストール

You can’t perform that action at this time.