matthew-mojira / cicero

GNU General Public License v3.0
0 stars 0 forks source link

ADTs #25

Open matthew-mojira opened 1 week ago

matthew-mojira commented 1 week ago

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).

matthew-mojira commented 2 days 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]