4 ms·
From the article you linked, those subdictionaries seem to support calling a function g[T1] inside a function f[T1, T2]. There’s a concept called polymorphic r
by codeflo 5y ago
From the article you linked, those subdictionaries seem to support calling a function g[T1] inside a function f[T1, T2].
There’s a concept called polymorphic recursion, supported by languages like Haskell, which goes beyond that and allows using arbitrary derived types in a function, in particular, in recursive calks.
My interpretation of the section in “non-monomorphisable functions” in the original article is that Go’s compilation strategy doesn’t handle that currently.
- Ericson2314 5y agoThese "GC shapes" a lot like GHC's "runtime reps": https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-Exts.html#t:RuntimeRep https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-E... GHC allows recursion that is "polymorphic in the types" but "monomorphic in the runtime reps". There is no reason why Go shouldn't allow polymorphic recursion that is "monomorphic in the gc shapes" either, though they might not have bothered to allow it yet.
- lalaithion 5y agoI think they do; the problem is that Go puts way less things behind a pointer than Haskell does. Every struct is its own runtime representation. If you change the example in https://github.com/golang/go/issues/48018 https://github.com/golang/go/issues/48018 to use a pointer indirection, I think it should work.
- Ericson2314 5y agoHopefully Haskell will get some monomorphizing generics and we will make less stuff boxed too!
- throwaway894345 5y agoMaybe I missed it in TFA, but what runtime type information is necessary for a generic function call?