Skip to content

Instantly share code, notes, and snippets.

@illusory0x0
Created June 27, 2025 08:37
Show Gist options
  • Select an option

  • Save illusory0x0/03db235e31455f81a16bacf08016c821 to your computer and use it in GitHub Desktop.

Select an option

Save illusory0x0/03db235e31455f81a16bacf08016c821 to your computer and use it in GitHub Desktop.
///|
type Zero
///|
type Succ[N]
///|
trait Nat {}
///|
pub impl Nat for Zero
///|
pub impl[N : Nat] Nat for Succ[N]
///|
type Vec[A, L] @list.T[A]
///|
pub fn[A] nil() -> Vec[A, Zero] {
@list.empty()
}
///|
pub fn[A, L : Nat] cons(x : A, xs : Vec[A, L]) -> Vec[A, Succ[L]] {
@list.construct(x, xs.inner())
}
///|
pub fn[A, L : Nat] tail(xs : Vec[A, Succ[L]]) -> Vec[A, L] {
match xs.inner() {
Empty => panic()
More(_, tail~) => tail
}
}
///|
pub fn[A, L : Nat] head(xs : Vec[A, Succ[L]]) -> A {
match xs.inner() {
Empty => panic()
More(x, ..) => x
}
}
test {
let xs = cons(1,cons(2,cons(3,nil())))
let ys : Vec[Int,Zero]= nil()
tail(xs) |> ignore
tail(ys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment