- Ubuntu 18.04 64bit
- opam 2.0.0
- ocaml 4.06.1 (最新は4.07だが、batteriesが未対応なので4.06で作る)
- dune 1.2.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object PTailRecursion { | |
def test(n: Int): Int = | |
if (n == 0) | |
test(n) | |
else | |
2 * test(n) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3, 4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util | |
def useMap(config: util.Map[String, String]): Unit = { | |
// "version" に対応する値が必ずあるとわかっているとする | |
val version = config.get("version") | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root ::= expression; | |
expression ::= A; | |
A ::= M ( "+" M | "-" M)*; | |
M ::= P ( "*" P | "/" P)*; | |
P ::= "(" expression ")" | number; | |
number ::= [0-9]+; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun add(x: Int, y: Int): Int { | |
x + y | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun fold_left f [] z = z | |
| fold_left f (x::xs) z = fold_left f xs (f z x); | |
val fold_left = fn : ('a -> 'b -> 'a) -> 'b list -> 'a -> 'a |