Skip to content

What's new in Haxe 4

Dan Korostelev edited this page Feb 8, 2019 · 50 revisions

New function type syntax

We're introducing the new syntax for specifying function types, now with clear separation of arguments from the return type and with support for argument names, which is very helpful for code self-documenting and better IDE support.

Example:

(name:String, age:Int)->Bool

Evolution proposal

Note that the old syntax is still supported, but the new one is preferable.

Arrow function syntax

Haxe now finally has the long-awaited arrow function syntax (a.k.a. short lambdas)! This is useful for code that has a lot of "short-and-sweet" callback functions, especially for the code written in the functional paradigm or the code that has to deal with asynchronous operations.

Example:

(a, b) -> a + b

Evolution proposal

Null-safety (experimental opt-in)

@:nullSafety

Final fields and locals

final a = 5

(can't mutate)

Final classes / interfaces without @:

final class Foo {}
final interface Bar {}

Unicode

"".length == 1

Eval

faster interpreter -> faster macros and scripts debugging support \o/

HashLink

bytecode and C, run-time fully conforming to haxe "spec"

Call-site inlining

inline f()

Auto-"using" for types

@:using(MyEnumTools) enum MyEnum {}

Abstract "resolved" field set support

@:op(a.b) function(field:String, value:Int):Int

(is that right?)

Key-value iterators

The for loop syntax now supports iteration over key+value pairs with a new syntax:

for (key => value in collection) {}

User-defined structures can support this by conforming to the new KeyValueIterable protocol.

Evolution proposal

Inline XML syntax

var a = <hi/>;

This will be available for macro processing as @:markup "<hi/>". XML strings are supposed to be parsed with a custom parser.

Simple example to convert XML to string with a macro function: http://try-haxe.mrcdk.com/#19734

Syntax for optional fields in "full" anon structs notation

{ var ?f:Int; }

Enum abstract without @:

enum abstract E(T) {}

Auto-numbering for enum abstracts

enum abstract E(Int) {
  var A; // 0
  var B; // 1
}
enum abstract E(String) {
  var A; // "A"
  var B; // "B"
}

Extern fields without @:

extern inline function f(...) {}

Removed implements Dynamic

Use custom abstracts if you need something like that

Added "type intersection" syntax

A & B (currently only for structures and type param constraints)

Removed comma-separated type param constraints syntax

C<T:(A,B)> now should be C<T:A&B>

Empty Map literals

var map:Map<Int, String> = [];

haxe.ds.ReadOnlyArray

var a:haxe.ds.ReadOnlyArray<Int> = [1, 2, 3];
a.push(4); // haxe.ds.ReadOnlyArray<Int> has no field push

New IDE services protocol

more features, json-based, currently undocumented, implemented in haxe language server and used in vshaxe

https://github.com/vshaxe/vshaxe/wiki/What%27s-New-in-2.0.0

Reworked command-line arguments and help message

Re-generated HTML externs