Hello everybody.
I'm trying to implement a simple MVC framework in Haxe (compiler v3.2.1), but I'm having problems with parameter types covariance and structural subtyping (if I understood the manual).
Basically, the program receives a request, passes it to a router class, that obtains the controller, that creates the response, that is dispatched by a dispatcher. I want a core package that does the basics, and several other packages that incrementally specificates it all. This way, I could have a HTTP package and a CLI package both inheriting from the Core one, changing only parameters, returns types and some concrete behavior. I have been a PHP programmer until very recently, and I think that is possible for that language. However, Haxe has a much more complex typing system, and I can't get to the perfect solution.
You can find a simplification of my code here:
http://try.haxe.org/#Fb9A8 . Demo- is the package for an example application using my framework.
As you can see, the return types can be incrementally specified "from top to bottom", but that is not true for the method parameters. Using the Core type all along will make the framework work, but I would prefer to "tighten them up" into the concrete expected types.
Type parametrization of the classes didn't work for me. If I parametrize the CoreRouter class to receive Http or CliRequests, I can't refer to it from the CoreApp class.
I have also tried doing some type casts but I think that is messy and the errors may raise on run time. I definitely prefer compile time errors.
Is it possible to incrementally specificate method parameter types in a Haxe class hierarchy? If it is not possible, or not advisable, any ideas for a workaround?
Thanks.