albrow / fo

An experimental language which adds functional programming features to Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot use r (variable of type *(partial)Ring[T]) as *(partial)Ring[T] value in assignment

icholy opened this issue · comments

What am I doing wrong here? https://play.folang.org/p/eFfTizZqyFQ

Syntax looks correct to me. This is a bug in the type-checker and I think I already know where to look. Will get to it as soon as I have a chance.

Here's a similar recursive type which panics when I try to compile.

package main

type A[T] struct {
  Next *A[T]
}

func main() {
  var a A[int]
  a.Next = &a
}

edit: ^^ Pretty sure this is what's been killing your playground.

@icholy your first issue is fixed in 9d30a36. As I suspected, the problem was in types/predicates.go which defines rules for whether two types are assignable to one another.

After I added a missing type parameter, the playground example compiles 😄

@icholy your second example is actually a separate issue, so I moved it to #15.

@icholy the first half of the issue had to do with declarations failing in the type checker. The second half of the issue occurred when you actually tried to use the recursive generic type (it resulted in a stack overflow error when trying to generate the appropriate concrete type). It is now fixed in 02a4bdb.

After a few changes, you can now actually use the Ring type in your original playground example :)

Awesome!