Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
Bug hunting 🎯

Simon Richardson SimonRichardson

👻
Bug hunting 🎯
View GitHub Profile
package ;
using Main.ListTypes;
using Main.Tuple2Types;
enum ListType<T> {
Nil;
Cons(head : T, tail : List<T>);
}
package ;
import haxe.macro.Expr;
import haxe.macro.Context;
@:remove @:autoBuild(CaseClassImpl.build())
extern interface CaseClass {}
class CaseClassImpl {
@SimonRichardson
SimonRichardson / Lens.hx
Last active December 16, 2015 20:09
Be dangerous and mutate a immutable Enum in haxe.
class Test {
static function main(){
var a = Cons(1, Nil);
trace(a);
trace(ListLens.mutate(a, 2));
trace(a);
/*
Output from the above traces - this is dangerous ;-)
@SimonRichardson
SimonRichardson / Isolates.hx
Last active December 16, 2015 22:39
This is a basic idea (proof of concept) to get isolates working in haxe by default. This should make it easier to make working with WebWorkers easier. Obviously you could use Actors to do the event managing behind the scenes and you would never know that you're using web workers (in theory)
package ;
@:remove
@:autoBuild(IsolateTypes.build())
extern interface Isolate {}
class Isolates {
private static var _isolates : Array<Class<Isolate>> = [];
@SimonRichardson
SimonRichardson / Test.hx
Last active December 17, 2015 03:09
Abstract enum issue when nesting enums. Gives error message: Test.hx:5: characters 8-39 : AType<AType<Int>> should be A<A<Int>>
class Test {
static function main(){
var val0 : A<Int> = a(1); // This is fine.
trace(val0);
var val1 : A<A<Int>> = a(a(1)); // This fails.
trace(val1);
}
}
enum AType<T> {
a(v : T);
@SimonRichardson
SimonRichardson / throwing-enums.hx
Last active December 17, 2015 07:48
Example of throwing enums.
class Test {
static function main(){
try {
//throw a(1);
throw b('1');
} catch (e : A) {
trace(e);
} catch (e : B) {
trace(e);
}
@SimonRichardson
SimonRichardson / do-if.hx
Created May 23, 2013 14:39
Open up the do keyword so it's more fluent. this will not compile - feature request!
// I think this should be valid syntax
do remove() if (once());
// which is similar to
do remove() while(once());
@SimonRichardson
SimonRichardson / Promise.js
Created July 10, 2013 16:01
bilby.js promise, I'd assume that you would want to do the following? The only downside I can foresee is that we loose the documentation of fantasy promises (through emu). I could be wrong and it could be a flag for this sort of stuff? You could possibly get rid of rigger for concat of files and just rely on require as well, might be worth exper…
var Promise = require('fantasy-promises');
/**
## isPromise(a)
Returns `true` if `a` is `Promise`.
**/
var isPromise = isInstanceOf(Promise);
bilby = bilby
// I've got quite a convoluted example, but it boils down to this, sort of.
(function(global){
function functionName(f) {
return f._name || f.name; // In istanbul this actually comes back as being not tested, even though it is.
}
global.functionName = functionName;
})(this);
@SimonRichardson
SimonRichardson / squishy-pants-gadt.js
Created August 1, 2013 16:11
Idea behind adding GADT to squishy-pants, it's not a nice as other languages, but this is the best we can do currently in a dynamic world.
var a = _.List(_.Some(_.Right(1)), _.Some(_.Left('Error')));
var result = a.match({
Some: {
Right: partial(
function(a) {
return a == 1;
},
_.identity
),
Right: _.constant(-1),