1. Alex Koz. 👾
  2. hx.quasix

Overview

HTTPS SSH

Smart & Sweet collection of neat macro magic solutions.

Build status

Compatibility

Compatible with targets:

  • Flash
  • Java
  • Neko
  • C++
  • PHP
  • JS
  • Python
  • Lua

C# in future plans.

Install:

Stable release: haxelib install quasix.

Development version:

haxelib hg quasix https://bitbucket.org/fzzr/hx.quasix

Then add to your hxml: -lib quasix.


Monomorph

Works only with Haxe 3.3.

This is a controllable internal compile-time-only type Unknown<..>. Its behavior look like we creating the Map using implicit cast in the abstract and type reification: var m:Map<Int, Bool> = new Map() with omitted type-parameters in the right part. But it have one extra step of resolving process - it's a custom resolving on macro.

Monomorph supports any field and types. Theoretically also supports fields in abstract classes.

Usage examples:

import hx.magic.Monomorph;

var a:haxe.ds.Vector<?Int -> Void> = new Monomorph(42);
var b:Monomorph = new haxe.ds.Vector<Monomorph>(42);
$type(b); // warns: haxe.ds.Vector<Unknown<0>>

b.set(0, 42);
$type(b); // warns: haxe.ds.Vector<Int>
import hx.magic.Monomorph as Unknown;

static var foo:Map<Unknown, Unknown>;
$type(foo); // warns: Map<Unknown<0>, Unknown<1>>

foo = new Map<String, Float>();
$type(foo); // warns: Map<String, Float>
static var foo:Map<String, Float>;
foo = new Unknown();
// foo = $type( new Unknown() ); // warns: Map<String, Float>
static var foo:Map<String, Unknown>;

// case 1:
foo = new Map<Unknown, Float>();
$type(foo); // warns: Map<String, Float>

// case 2:
foo = new Map<Unknown, Bool>();
$type(foo); // warns: Map<String, Bool>

Usage recommendation

I strongly recommend to use new feature of Haxe 3.3 - import.hx. Simply create file import.hx in the root of your class-path and add into it all needed imports and usings:

import hx.magic.Monomorph;