I wanted to learn a bit more about the haxe type system so I just implemented the
Elm example which uses the type either, to do an array partition based on the type either.
I tried to translate everything line to line, so I conclude that the haxe type system actually misses nothing from a complex type system as in Elm's. Except by one detail: in the original Elm code the partition function can specify that the return type is a tuple of two arrays from type A and type B.
// Original Elm Signature:
partition : List (Either a b) -> (List a, List b)
// My Haxe version
static function partition<A,B>(eithers:EitherArray<A,B>):Array<EitherArray<A,B>>
The problem of my return type is that it doesn't enforce the whole correctness of the function just by using the type system (with a wrong implementation still the groups could be mixed).
How could I do that in haxe? Something like that doesn't even compile:
static function partition<A,B>(eithers:EitherArray<A,B>):Array<[Array<A>,Array<B>]>
If there is a concept or similar functionality could someone point me to it?
Since the return array has a fixed size, would it be possible a solution based on macros?
Thanks!