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
var Option = require('fantasy-options') | |
var Some = Option.Some; | |
var None = Option.None; | |
var Compose = function(x){ | |
this.val = x; | |
} | |
Compose.prototype.map = function(f){ | |
return new Compose(this.val.map(function(u){return u.map(f); })); |
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 scalaz._ | |
// A right Kan extension of `F` along itself, constrained by `C`. | |
trait RCodensity[C[_], F[_], A] { | |
def apply[R:C](k: A => F[R]): F[R] | |
} | |
object RCodensity { | |
implicit def codensityMonad[C[_], F[_]]: Monad[({type f[x] = RCodensity[C,F,x]})#f] = | |
new Monad[({type f[x] = RCodensity[C,F,x]})#f] { |
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
// Some minimal class for values with units | |
// (nothing exciting going on...) | |
function Unit(name,val) { | |
this.name = name; | |
this.val = val; | |
} | |
Unit.prototype.toString = function() { | |
return this.val + " " + this.name; | |
} |
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
class VerEx | |
{ | |
public static function main() | |
{ | |
var test = new VerEx() | |
.startOfLine() | |
.then("http") | |
.maybe("s") | |
.then("://") | |
.maybe("www.") |
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
macro _arms { | |
case (default => $value:expr) => { | |
else { | |
return $value; | |
} | |
} | |
case (case $cond:expr => $value:expr) => { | |
if($cond) { | |
return $value; | |
} |
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
var State = require('fantasy-states'), | |
Tuple2 = require('fantasy-tuples').Tuple2, | |
// Tuple2 Number Number | |
initial = Tuple2(0, 1), | |
// State (Tuple2 Number Number) Number -> State (Tuple2 Number Number) Number | |
next = discard( | |
State.modify(function(t) { | |
return Tuple2(t._1 + 1, (t._1 + 1) * t._2); |
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
class Main { | |
static public function main () { | |
var v = Printf.sprintf("The sum of $i and $i is $s.", 3, 5, "8"); | |
trace(v); // The sum of 3 and 5 is 8. | |
} | |
} |
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 precog.macro.ValueClass; | |
class ABC implements ValueClass { | |
var a: Int; | |
var b: Bool; | |
var c: String; | |
} | |
/* | |
class ABC extends ValueClass { |
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 haxe.macro.Context; | |
import haxe.macro.Expr; | |
import haxe.macro.Type; | |
class AbstractBuilder { | |
macro static public function build():Array<Field> { | |
var fields = Context.getBuildFields(); | |
var cCur = Context.getLocalClass().get(); | |
var fieldMap = [for (f in fields) f.name => true]; | |
function loop(c:ClassType) { |
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 haxe.macro.Context; | |
import haxe.macro.Expr; | |
import haxe.macro.Type; | |
using Lambda; | |
/** | |
Old school abstract class. | |
Classes that implements it, and their sub-classes, will be able to declare abstract methods (methods that without body). | |
There will be a check in compile-time such that no public constructor is allowed without all abstract methods implemented. | |
*/ |