Can parameters be final in Haxe 4?

I tried the obvious syntax

   function out( final  x : String ) { ... }

The reason I am looking is that I have a macro to support monads. Currently

   seq( (var x = p),
           q )

turns in to

    p.bind( (x) -> q )

I’d like to extend the macro so it converts

   seq( (final x = p),
           q )

into

    p.bind( (final x) -> q )

No, I don’t think there’s a final modifier for parameters, but since you’re macro-processing anyway, you can use variable shadowing and generate final x = x in the very beginning of a function body, so the x argument would be overshadowed by the final local variable of the same name.

So, seq((final x = p), q) to p.bind(x -> {final x = x; q}).

3 Likes