Created
June 27, 2025 08:37
-
-
Save illusory0x0/03db235e31455f81a16bacf08016c821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///| | |
| 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 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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