What is Haxe

Nicolas Cannasse
@ncannasse
WWX 2013

One Year Of Haxe

3.0 available TODAY

Haxe 3.0

Haxe 3.0 - Properties

In 2.x:

class Example {
	public var name(default,setName) : String;
	public var age(getAge,setAge) : Int;
}
	

In 3.x:

class Example {
	public var name(default,set) : String;
	@:isField public var age(get,set) : Int;
	function set_name(v) {
		//....
	}
}
	

Haxe 3.0 - bind()

In 2.x:

		function onClicked(item:Item) {
		}
		//...
		for( item in allItems )
			item.elt.click(callback(onClicked,item));
	

In 3.x:

		for( item in allItems )
			item.elt.click(onClicked.bind(item));
	

Haxe 3.0 - bind()

More use cases:

		function div(x,y) return x / y;
		div(1,2);
		var invert = div.bind(1);
		invert(2);
		var percent = div.bind(_,100);
		percent(5);
	

Haxe 3.0 - Map

In 2.x:

		var byName : Hash<MyObject> = new Hash();
		var byId : IntHash<MyObject> = new IntHash();
	

In 3.x:

		var byName : Map<String,MyObject> = new Map();
		var byId : Map<Int,MyObject> = new Map();
		// but also:
		var objectMap : Map<MyObject,MyOtherObject> = new Map();
		var enumMap : Map<MyEnum,Something> = new Map();
	

Literal maps:

		[ "Hello" => "World", "WWX" => "Rocks!" ]
	

Haxe 3.0 - API changes

Haxe 3.0 - String Interpolation

Haxe 3.0 - Pattern Matching

	enum E {
		Leaf;
		Value( v : Int );
		Tree( left : E, right : E );
	}
	

Different cases:

	switch( e ) {
	case Leaf:
	case Value(0):
	case Value(x) if( x > 0 ): /* guard */
	case Tree(Leaf,Value(x)):
	case all: throw "Error "+all;
	}
	

Haxe 3.0 - Array Comprehension

In 2.x:

	var arr = new Array();
	for( i in 0...10 )
		arr.push(i);
	

In 3.x:

	var arr = [for( i in 0...10 ) i];
	

Haxe 3.0 - Array Comprehension

Inner loops and filters:

	var arr = [
		for( x in 0...10 )
			for( y in 0...10 )
				if( x+y < 10 ) x*y;
	];
	

Map comprenhension:

	var m = [for( x in 0...10 ) x => x*x];
	

Haxe 3.0 - Abstract types

	abstract Meter(Int) {
		public function new(i:Int) this = i;
		public function toInt() : Int return this;
	}
	abstract Kilometer(Float) {
		public function new(i:Float) this = i;
		public function toInt() : Float return this;
	}
	
		var m = new Meter(1000);
		var k = new Kilometer(1.0);
	

Compiles to:

		var m = 1000;
		var k = 1.0;
	

Haxe 3.0 - Abstract types

Auto-cast from:

		abstract Meter(Int) {
			//...
			@:from static inline function fromInt(i) {
				return new Meter(i);
			}
		}
	

Now allows:

		var x : Meter = 10;
	

Haxe 3.0 - Abstract types

Auto-cast to:

		abstract Meter(Int) {
			//...
			@:to inline function toKilometer() {
				return new Kilometer(this/1000.0);
			}
		}
	
		var x : Kilometer = new Meter(100);
	

Compiles to:

		var x = 0.1;
	

Haxe 3.0 - More Abstract types

Haxe 3.0

Announcement:

We're now on Github!

http://github.com/HaxeFoundation

Haxe Foundation

Haxe Foundation

Our partners:

Haxe Foundation

Our plans:

What is Haxe

Haxe Misperceptions

What is Haxe

What is Haxe

A new way to define it:

«Haxe, The cross-plaform toolkit»

New Haxe Website

More Tooling

Haxedit

Haxe Foundation

The way we work:

Don't forget

Thank you!

Done with http://github.com/ncannasse/hxslides