Open matthew-mojira opened 1 month ago
example for #20. this is sort of like dependent types, but it's not because we have no static type checking
func list/add(obj: box[list[T, n]], new: T) -> box[list[T, n + 1]] {
const lst = unbox obj
obj <- list[T, n + 1](func (i) -> if i < n then lst[i] else new)
}
Note, types do not have to be parameterized by other types. They can be parameterized by any value, which must satisfy a type pattern. So a type definition of list
may be:
type list[T: type,
n: int when n >= 0]
Should these be libraries? (Can they be libraries?)
The first three are the essential ones, while the other four can be constructed from the other three (technically, it could all be from list but I consider set and map also just as essential).