By supporting dependent types, you support generics.
id[T](x: T) = x
/* Implicitly expanded to: */
id[T: Type](x: T): T = x;
id
is an identifier, just like in x = 5
.[...]
denotes an implicit argument. This is an argument the compiler is allowed to implicitly make any value it sees convenient.T: Type
is saying T is a Type (this could probably be made more generic).Pair(A, B) = Struct {
left: A;
right: B;
};
Pair: (Type, Type) -> Type
Maybe tuples and objects can be interpreted as both a type and a value? I.e (1, 2)
and (Int, Int)
are both tuples, but you can write (1, 2): (Int, Int)
.
Could you do something like (1, Int): (Int, Type)
?
Is this something special with :
? Is it saying “if the two sides have the same constructor, recurse”? Could this cause ambiguities? Could this apply to other constructors? User defined structures?
Expr: Type where {
Add(left: Expr, right: Expr): Expr;
Sub(left: Expr, right: Expr): Expr;
Const(n: Int): Expr;
};
Expr: Type where {
Add: (Expr, Expr) -> Expr;
Sub: (Expr, Expr) -> Expr;
Const: Int -> Expr;
};