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
def classify(xts:List[('a,Type.T)], ini:'b, addf:('b,'a)=>'b, addi:('b,'a,Type.T)=>'b):'b = { | |
xts.foldLeft(ini) { | |
case (acc, (x, t)) => t match { | |
case Type.Unit() => acc | |
case Type.Float() => addf(acc, x) | |
case _ => addi(acc, x, 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
// orignal code http://openpear.org/package/IO_MIDI/downloads | |
package midi | |
case class Midi(header:Header,tracks:List[Track]) | |
trait Chunk | |
case class Header(format:Int,numberOfTracks:Int,divisionFlag:Int,division:Int) extends Chunk | |
case class Track(List[Event]) extends Chunk | |
trait Event | |
class IO_MIDI { |
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
trait Eq1 { | |
fn eq1(&self, o: &Self) -> bool; | |
} | |
trait Eq2 { | |
fn eq2(&self, o: &Self) -> bool; | |
} | |
struct I {i:int} impls Eq1, Eq2 { | |
fn eq1(&self, o: &I) -> bool { (*o).i == (*self).i } | |
fn eq2(&self, o: &I) -> bool { (*o).i == (*self).i } | |
} |
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
var traits = {}; | |
function trait(name, methods) { | |
traits[name] = methods; | |
} | |
function struct() { | |
var args = arguments; | |
// インターフェイスを作成 |
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
open Format | |
let pp_ls f ppf ls = | |
let rec loop ppf = function | |
| [] -> () | |
| [x] -> fprintf ppf "%a@?" f x | |
| x::xs -> fprintf ppf "%a, %a" f x loop xs | |
in | |
fprintf ppf "{%a}@?" loop ls | |
let pp_i ppf i = fprintf ppf "%d@?" i |
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 set | |
object main extends App { | |
def power[A](t: Set[A]): Set[Set[A]] = { | |
@annotation.tailrec | |
def pwr(t: Set[A], ps: Set[Set[A]]): Set[Set[A]] = | |
if (t.isEmpty) ps | |
else pwr(t.tail, ps ++ (ps map (_ + t.head))) | |
pwr(t, Set(Set.empty[A])) //Powerset of ∅ is {∅} | |
} |
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
var traits = {}; | |
var insts = {}; | |
function trait(name, methods) { | |
traits[name] = methods; | |
insts[name] = {}; | |
} | |
function struct(name, params, impls, body) { | |
function findTraitName(x) { |
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
var traits = {}; | |
var insts = {}; | |
function trait(name, methods) { | |
traits[name] = methods; | |
insts[name] = {}; | |
} | |
function struct(typeName, params, traitNames, bodys) { |
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
use std::f64::consts::PI; | |
trait Shape { fn new(area: f64) -> Self; } | |
struct Circle { radius: f64 } | |
struct Square { length: f64 } | |
impl Shape for Circle { | |
fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } } | |
} | |
impl Shape for Square { | |
fn new(area: f64) -> Square { Square { length: area.sqrt() } } |
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
#include <stdio.h> | |
extern "C" { | |
void printi(int i) { | |
printf("%d\n", i); | |
} | |
typedef void (*A_p)(struct A*); | |
struct A { | |
static void _new(struct A* self) { |
OlderNewer