build: separate compiler and libs

This commit is contained in:
Li Jie
2025-01-07 21:49:08 +08:00
parent b0123567cd
commit 1172e5bdce
559 changed files with 190 additions and 176 deletions

View File

@@ -0,0 +1,36 @@
package main
func main() {
recursive()
}
func recursive() {
type T int
if got, want := recur1[T](5), T(110); got != want {
panic("error")
}
}
type Integer interface {
~int | ~int32 | ~int64
}
func recur1[T Integer](n T) T {
if n == 0 || n == 1 {
return T(1)
} else {
return n * recur2(n-1)
}
}
func recur2[T Integer](n T) T {
list := make([]T, n)
for i, _ := range list {
list[i] = T(i + 1)
}
var sum T
for _, elt := range list {
sum += elt
}
return sum + recur1(n-1)
}