Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot call function with self-referencing signature (Y combinator) #48

Open
cosmos72 opened this issue May 12, 2018 · 1 comment
Open

Comments

@cosmos72
Copy link

the following compiles:

type F func(F)
func Y(f F) {
	println("Y combinator")
}

but attempts to call Y fail:

gi> Y(Y)

oops: 'problem detected during Go static type checking: 'cycles not allowed: 'parent:'func(main.F)' -> child:'main.F' completes a cycle''' on input 'Y(Y)'.

Go playground has no problem running it: https://play.golang.org/p/l2bWUnAETIx

@cosmos72 cosmos72 changed the title cannot call Y combinator cannot call function with self-referencing signature (Y combinator) May 12, 2018
@glycerine
Copy link
Contributor

glycerine commented May 12, 2018

Thanks @cosmos72 !

Notes to self: gopherjs handles this fine. Luajit runs it fine. It is purely a typechecking layer issue.

gi> Y                                                                                                    
func Y(f F)     { println("Y combinator") }                                                              
                                                                                                         
elapsed: '114.824µs'                                                                                     
gi> Y(nil)                                                                                               
oops: 'problem detected during Go static type checking: 'cycles not allowed: 'parent:'func(main.F)' -> child:'main.F' completes a cycle''' on input 'Y(nil)'                                                     
gi> :r                                                                                                   
Raw LuaJIT language mode.                                                                                
raw luajit gi> Y(nil)                                                                                    
Y combinator                                                                                             
                                                                                                         
elapsed: '46.878µs'                                                                                      
raw luajit gi>  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants