go: cmd/go2go: Recursive generics hang the playground.

I tried this on the playground:

package main

import (
	"fmt"
)

type Nil struct {
}

type Tuple(type A, B) struct {
	A A
	B B 
}

func (u Tuple(A,B)) Head() A {
	return u.A
}

func (u Tuple(A,B)) Tail() B {
	return u.B
}

func New(type A,B)(a A, b B) Tuple(A, B) {
	return Tuple(A, B){a, b}
}


func (u Tuple(A,B)) Append(v A) Tuple(Tuple(A,B), A) {
	return Tuple(Tuple(A,B), A){u, v}
}

func NewList(type T)(v T) Tuple(T, Nil) {
	return Tuple(T, Nil){v,Nil{}}
}


func main() {
	t := Tuple(int,Tuple(int,Tuple(int,Nil))){}
	l := NewList(7) 
	fmt.Printf("Foo: %v!\n%v\n", t, l)
}

But it hung the playground instance I was working on indefinitely without crashing. Hopefully it didn’t break anything serious, a new instance of the pleyground seems ok. I’m not sure if such recursion as in Append should be allowed or not, although it would be handy. If not, then the recursion should e detected promptly somehow to prevent such hangs.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

It is not desirable that Go generics be Turing complete. If you are able to demonstrate that, please do share it. Thanks.