HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[haxe.org/manual] Constraints #143

Open utterances-bot opened 3 months ago

utterances-bot commented 3 months ago

Constraints - Haxe - The Cross-platform Toolkit

Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.

https://haxe.org/manual/type-system-type-parameter-constraints.html

thomasjwebb commented 3 months ago

One thing that would help to let people know is that you can constrain to numeric using Float, e.g.,

function add<T:Float>(a:T, b:T):T {
    return a + b;
}

This will even work with Int and I can confirm on the hxcpp target at least it does monomorph to a class that uses ints, no float conversion.