Back to Search View Original Cite This Article

Abstract

<jats:p>This paper explores the implementation of extension methods in GoNext, a dialect of the Go programming language that transpiles into standard Go code. Go is a statically compiled language with a lightweight runtime, excellent concurrency support, fast compilation, and a large ecosystem, but it also has a relatively simple type system that does not allow defining methods on types outside the package where they are declared. Extension methods address this limitation by allowing developers to add methods to existing types – including those defined in third-party libraries or the Go standard library – without modifying their source code. The authors review how extension methods are implemented in other mainstream pro-gramming languages (C#, Swift, Kotlin, Rust, Scala) and compare them with the related con-cept of uniform function call syntax, then propose a GoNext-specific approach: extension functions are declared using a new extension keyword before a regular function declaration and are transpiled into ordinary free functions by simply removing that keyword, while call sites are rewritten from method-call syntax (value.Method(params)) into explicit function calls (package.Method(value, params)) using a resolution algorithm based on Go's type unifi-cation rules. The paper also describes an import extension modifier that allows treating all functions in an existing Go package as extension methods without adding unnecessary wrap-pers. The proposed approach is demonstrated on a complete example showing how chained extension method calls are transformed into nested function calls during transpilation. The paper demonstrates that this approach achieves zero runtime overhead, maintains full two-way interoperability with standard Go, and – as an additional benefit – enables support for generic methods, a feature intentionally omitted from Go due to unresolved questions around existing interfaces implementation. The proposed mechanism leverages transpilation as a practical strategy for extending a language's capabilities while reusing its existing compiler and runtime infrastructure.</jats:p>

Show More

Keywords

extension methods existing function paper

Related Articles