Crystal: Request for generic alias

Created on 11 Jun 2016  路  2Comments  路  Source: crystal-lang/crystal

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.

feature compiler

Most helpful comment

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 

All 2 comments

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 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  78Comments

sergey-kucher picture sergey-kucher  路  66Comments

asterite picture asterite  路  71Comments

RX14 picture RX14  路  62Comments

benoist picture benoist  路  59Comments