This file contains 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
package fpinscala.datastructures | |
sealed trait List[+A] | |
case object Nil extends List[Nothing] | |
case class Cons[+A](head : A, tail : List[A]) extends List[A] | |
object List { | |
def apply[A](as : A*) : List[A] = | |
if (as.isEmpty) Nil | |
else Cons(as.head, apply(as.tail : _*)) |
This file contains 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
from base64 import decodestring, encodestring | |
from xml.etree.ElementTree import ElementTree | |
import sys | |
import io | |
from PIL import Image | |
inputfile = sys.argv[1].strip() | |
outputfile = sys.argv[2].strip() | |
opacity = sys.argv[3].strip() |
This file contains 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
enum Color { | |
R; B; BB; NB; | |
} | |
enum RedBlackTree<T> { | |
T(c : Color, l : RedBlackTree<T>, v : T ,r : RedBlackTree<T>) : RedBlackTree<T>; | |
E : RedBlackTree<T>; | |
EE : RedBlackTree<T>; | |
} |
This file contains 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
let alphabet = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; | |
'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; | |
'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z'] | |
let rec nth l = function | |
0 -> List.hd l | |
| i -> nth (List.tl l) (i - 1) | |
let rec trans1 = function | |
[] -> [] |
This file contains 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
class AliceFactory2 implements PersonInterface<Alice> { | |
public function new() { } | |
public function make() : AbsPerson<Alice> { | |
return Alice.AliceConst; | |
} | |
} |
This file contains 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
abstract AbsPerson<X>(Person<X>) { | |
public function new(x) { | |
this = x; | |
} | |
@:from public static function fromAlice(a : Alice) : AbsPerson<Alice> { | |
return new AbsPerson(A(a)); | |
} | |
@:from public static function fromBob(b : Bob) : AbsPerson<Bob> { |
This file contains 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
enum List<T> { | |
Cons(h : T, t : List<T>, n : Int) : List<T>; | |
Nil : List<T>; | |
} | |
enum StreamCell<T> { | |
Cons(h : T, t : Stream<T>, n : Int) : StreamCell<T>; | |
Nil : StreamCell<T>; | |
} | |
typedef Stream<T> = Void -> StreamCell<T> |
This file contains 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
enum List<T> { | |
Cons(h : T, t : List<T>); | |
Nil; | |
} | |
enum StreamCell<T> { | |
Cons(h : T, t : Stream<T>) : StreamCell<T>; | |
Nil : StreamCell<T>; | |
} |
This file contains 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
enum List<T> { | |
Cons(h : T, t : List<T>); | |
Nil; | |
} | |
enum StreamCell<T> { | |
Cons(h : T, t : Stream<T>) : StreamCell<T>; | |
Nil : StreamCell<T>; | |
} |
This file contains 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
enum StreamCell<T> { | |
Cons(x : T, t : Stream<T>) : StreamCell<T>; | |
Nil : StreamCell<T>; | |
} | |
typedef Stream<T> = Void -> StreamCell<T> | |
class LazyList<T> { | |
private var body : Stream<T>; | |
private static var nil = function () : StreamCell<T> { | |
return Nil; |