In Crystal, we can alias a type like this:
alias Foo = SomeGeneric(Int32)
And all Foo
will be replaced with SomeGeneric(Int32)
.
But we cannot alias as a generic type like this:
alias Bar(T) = TwoTypesGeneric(String, T)
Can Crystal support this syntax for a generic alias?
It will be useful to avoid writing long type name.
I think it's possible and shouldn't be that hard to do.
Bump
My use-case isn't for long names, but for something like:
record Success(T), value : T
record Failure, message : String
alias Result(T) = Success(T) | Failure
This mimic Functional Programming's Variants:
// In F#
type Result<'a> =
| Success of 'a
| Failure of string
Most helpful comment
Bump
My use-case isn't for long names, but for something like:
This mimic Functional Programming's Variants: