Joel Kleier's Electric Froth

up

Haxe Function Signatures

by Joel Kleier on 2013-03-06


Just a quick note about this function signature:

#!haxe
Dynamic -> Void

Dynamic generally means any type in Haxe. However, it does not mean Void.

For example, if you have this:

#!haxe
var func:Dynamic -> Void;

You cannot assign func a function that has a void parameter list. It DOES require a parameter, but that parameter can be of any type.

IE, this is bad:

#!haxe
function foo() {}

// foo is of type Void -> Void, not Dynamic -> Void
func = foo;

But this is good:

#!haxe
function foo(bar:Dynamic) {}

func = foo;

It may seem kinda obvious, but I was tripped up on it because I thought Dynamic could represent any type of value, including a Void parameter list. Which, in hindsight, seems kind of ridiculous, but none-the-less, it happened.

NOTE This was written for Haxe 2.10